Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] azure-communication-email:1.1.0-beta.1 - cannot send email with attachments #43462

Open
ejossev opened this issue Dec 18, 2024 · 0 comments
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@ejossev
Copy link

ejossev commented Dec 18, 2024

Describe the bug
Cannot send email with attachments with version 1.1 beta1

Exception or Stack Trace
The error I'm getting back is:
Status code 400, "{"error":{"code":"BadRequest","message":"Request body validation error. ContentBytes invalid. Should be base64.","target":null,"details":null,"innererror":null}}"

To Reproduce
Try to send the mail with attachments, see code below.

Code Snippet

@Service
public class AzureMailService implements MessagingService {
    @Autowired
    public AzureMailService(
            @Value("${ch.hygiaso.azure-email.connection-string}")
            String connectionString,
            @Value("${ch.hygiaso.azure-email.sender-address}")
            String senderAddress
    ) {
        emailClient = new EmailClientBuilder()
                .connectionString(connectionString)
                .buildAsyncClient();
        this.senderAddress = senderAddress;
    }

    public void sendMessage(String recipientAddress, String subject, String body, FileContentDTO... attachments) {
        logger.debug("Sending notification email to {}", recipientAddress);
        EmailMessage message = new EmailMessage()
                .setSenderAddress(senderAddress)
                .setToRecipients(recipientAddress)
                .setSubject(subject)
                .setBodyHtml(body)
                .setAttachments(Arrays.stream(attachments).map(att -> new EmailAttachment(att.getName(), att.getContentType(), BinaryData.fromBytes(att.getContent()))).toList());
        var poller = emailClient.beginSend(message);
        poller.subscribe(response -> {
                    if (response.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
                        logger.trace("Successfully sent the email (operation id: {})", response.getValue().getId());
                    }
                },
                error -> logger.error("Error occurred while sending email to {}: {}", anonymizeEmailForLogging(recipientAddress), error.getMessage()));
        logger.debug("Email queued for sending");
    }
}

Expected behavior
E-mail is queued

Screenshots
N/A

Setup (please complete the following information):

  • OS: Azure web apps - no clue what is running there
  • IDE: N/A
  • Library/Libraries: com.azure:azure-communication-email:1.1.0-beta.1
  • Java version: 17
  • App Server/Environment: Azure web apps
  • Frameworks: spring boot

Additional context
Works well with 1.0.18. I want to upgrade to 1.1 version to be able to set CID and refer images from the html content, but pure change of the package version causes this issue.

Information Checklist

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

1 participant