microsoftgraph / microsoftgraph/msgraph-sdk-java

Concurrent requests to send emails will generate duplicate emails, and the number does not match.

Open
#2,494 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status:waiting-for-triage
Dominant language
Java
Stars
444
Forks
154
Avg merge
18h 28m
Merged PRs (30d)
4

Description

Hello!

I used Postman to iterate 160 times to send emails, and actually received 160+ emails. The number of emails received is random and does not match the number, which means duplicate emails are generated.

Image Image Image

@PostMapping("/test") public void SysEmailController() { GraphEmailSender.testInfo(); }

`

import com.azure.identity.ClientSecretCredential;
import com.azure.identity.ClientSecretCredentialBuilder;
import com.microsoft.graph.models.EmailAddress;
import com.microsoft.graph.models.ItemBody;
import com.microsoft.graph.models.Message;
import com.microsoft.graph.models.Recipient;
import com.microsoft.graph.serviceclient.GraphServiceClient;
import com.microsoft.graph.users.item.sendmail.SendMailPostRequestBody;

import java.util.Collections;
import java.util.List;

public class GraphEmailSender {
// 配置参数
private static final String CLIENT_ID = "";
private static final String CLIENT_SECRET = "";
private static final String TENANT_ID = "";
private static final String SENDER_EMAIL = "";
private static final String[] SCOPES = new String[] { "https://graph.microsoft.com/.default" };

private static GraphServiceClient graphClient;


static {
    try {
        final ClientSecretCredential credential = new ClientSecretCredentialBuilder()
                .clientId(CLIENT_ID)
                .tenantId(TENANT_ID)
                .clientSecret(CLIENT_SECRET)
                .build();

        if (null == credential) {
            throw new Exception("Unexpected error");
        }

        graphClient = new GraphServiceClient(credential, SCOPES);
    } catch (Exception e) {
        System.err.println("init GraphServiceClient error: " + e.getMessage());
        e.printStackTrace();
    }
}

public static void testInfo() {
    try {

        Message message = new Message();
        message.setSubject("test mail - Microsoft Graph API");

        ItemBody body = new ItemBody();
        body.setContent("Microsoft Graph API mail。");
        message.setBody(body);

        Recipient recipient = new Recipient();
        EmailAddress emailAddress = new EmailAddress();
        emailAddress.setAddress("");
        recipient.setEmailAddress(emailAddress);
        List<Recipient> recipients = Collections.singletonList(recipient);
        message.setToRecipients(recipients);

        SendMailPostRequestBody sendMailPostRequestBody =
                new SendMailPostRequestBody();
        sendMailPostRequestBody.setMessage(message);

        //
        graphClient.users()
                .byUserId(SENDER_EMAIL)
                .sendMail()
                .post(sendMailPostRequestBody);

        System.out.println("send success!"+Thread.currentThread());

    } catch (Exception e) {
        System.err.println("error: " + e.getMessage());
        e.printStackTrace();
    }
}

}`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided @PostMapping("/test") entry point and GraphEmailSender.testInfo(), then reproduce the 160 concurrent sendMail requests using the shown Microsoft Graph client code. Compare request and delivery counts to determine whether the behavior is in the SDK or the calling application. Done means a reproducible SDK defect with a focused test or clear evidence that no SDK change is indicated.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.