【发布时间】:2022-05-25 01:06:03
【问题描述】:
我想利用增加的 SES 发送限制从 10MB 到现在高达 40MB since September 2021 来发送更大的 Excel 文件作为电子邮件附件。
我使用了official code example,但不幸的是,我的大小不能超过 10MB。
我得到错误:
消息长度超过 10485760 字节长:12148767
我正在使用
software.amazon.awssdk:ses的最新版本,即 2.17.196。static Region region = Region.EU_CENTRAL_1; static SesClient client = SesClient.builder().region(region).build(); public static void sendemailAttachment(SesClient client, String sender, String recipient, String subject, String bodyText, String bodyHTML, String fileName, // must include .xlsx String fileLocation) throws AddressException, MessagingException, IOException { java.io.File theFile = new java.io.File(fileLocation); byte[] fileContent = Files.readAllBytes(theFile.toPath()); Session session = Session.getDefaultInstance(new Properties()); // Create a new MimeMessage object MimeMessage message = new MimeMessage(session); // Add subject, from and to lines message.setSubject(subject, \"UTF-8\"); message.setFrom(new InternetAddress(sender)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient)); // Create a multipart/alternative child container MimeMultipart msgBody = new MimeMultipart(\"alternative\"); // Create a wrapper for the HTML and text parts MimeBodyPart wrap = new MimeBodyPart(); // Define the text part MimeBodyPart textPart = new MimeBodyPart(); textPart.setContent(bodyText, \"text/plain; charset=UTF-8\"); // Define the HTML part MimeBodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent(bodyHTML, \"text/html; charset=UTF-8\"); // Add the text and HTML parts to the child container msgBody.addBodyPart(textPart); msgBody.addBodyPart(htmlPart); // Add the child container to the wrapper object wrap.setContent(msgBody); // Create a multipart/mixed parent container MimeMultipart msg = new MimeMultipart(\"mixed\"); // Add the parent container to the message message.setContent(msg); // Add the multipart/alternative part to the message msg.addBodyPart(wrap); // Define the attachment MimeBodyPart att = new MimeBodyPart(); DataSource fds = new ByteArrayDataSource(fileContent, \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\"); att.setDataHandler(new DataHandler(fds)); String reportName = fileName; // include .xlsx att.setFileName(reportName); // Add the attachment to the message. msg.addBodyPart(att); try { System.out.println(\"Attempting to send an email through Amazon SES \" + \"using the AWS SDK for Java...\"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); message.writeTo(outputStream); ByteBuffer buf = ByteBuffer.wrap(outputStream.toByteArray()); byte[] arr = new byte[buf.remaining()]; buf.get(arr); SdkBytes data = SdkBytes.fromByteArray(arr); RawMessage rawMessage = RawMessage.builder() .data(data) .build(); SendRawEmailRequest rawEmailRequest = SendRawEmailRequest.builder() .rawMessage(rawMessage) .build(); client.sendRawEmail(rawEmailRequest); } catch (SesException e) { System.err.println(e.awsErrorDetails().errorMessage()); // <-- System.exit(1); } System.out.println(\"Email sent with attachment\"); }任何想法为什么我仍然收到有关 10 MB 电子邮件大小限制的错误?
-
您多久发送一次这些电子邮件?这是至少每秒一条 40MB 的消息,还是每秒发送超过一条 40MB 的消息? AWS SES 将带宽限制在 10MB 以上。
-
@ErmiyaEskandary 它在测试环境中,只发送了 1 封电子邮件,但它仍然出现。是的,我联系了支持人员,但它似乎是 40MB 的默认报价,没有必要或不可能提出增加限制的请求。他们提到“要实现发送 40MB 大小的电子邮件的目标,您需要使用 SES v2 API 或 SMTP。”我相信这已经通过使用“software.amazon.awssdk:ses:2.17”来实现。 196\"
-
@ErmiyaEskandary 就像你说的那样。我必须使用单独的包 \"software.amazon.awssdk:sesv2:2.17.196\" 才能访问 SesV2Client 文件。对代码进行了一些小的调整,现在它可以工作了。非常感谢你!
-
非常欢迎,很高兴你让它工作。
标签: java amazon-web-services amazon-ses aws-sdk-java-2.0 amazon-simple-email-service