Java 如何通过google app engine发送带有CSV文件附件的gmail邮件
我正在尝试通过google app engine发送一封带有csv附件的电子邮件,收件人没有收到邮件。当我在Google App Engine中查看日志时,也没有报告任何错误。出了什么问题?有人能告诉我,是否有可能通过邮件发送csv文件作为附件使用谷歌应用程序引擎?如果是的话,你能告诉我怎么做吗Java 如何通过google app engine发送带有CSV文件附件的gmail邮件,java,google-app-engine,jakarta-ee,Java,Google App Engine,Jakarta Ee,我正在尝试通过google app engine发送一封带有csv附件的电子邮件,收件人没有收到邮件。当我在Google App Engine中查看日志时,也没有报告任何错误。出了什么问题?有人能告诉我,是否有可能通过邮件发送csv文件作为附件使用谷歌应用程序引擎?如果是的话,你能告诉我怎么做吗 Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null);
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("xxx@gmail.com"," Admin"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(emailto, "Mr. User"));
msg.setSubject("Expence Tracker with Attachment");
String htmlBody=msgbody;
byte[] attachmentData= attach.getBytes();
Multipart mp = new MimeMultipart();
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(htmlBody, "text/html");
mp.addBodyPart(htmlPart);
MimeBodyPart attachment = new MimeBodyPart();
attachment.setFileName("myfile.csv");
attachment.setContent(attachmentData, "text/comma-separated-values");
mp.addBodyPart(attachment);
msg.setContent(mp);
//resp.getWriter().println("Mail Details :To- "+emailto);
} catch (AddressException e) {
resp.getWriter().println("Mail Details :Error "+e);
} catch (MessagingException e) {
resp.getWriter().println("Mail Details :Error "+e);
}
这是发送CSV附件的示例。CSV在blobstore中。 它在Python中使用GAE邮件和blobstore API。将其转换为Java并不困难
blob_key = files.blobstore.get_blob_key(file_name)
blob_info = blobstore.BlobInfo.get(blob_key)
blob_reader = blobstore.BlobReader(blob_key)
message = mail.EmailMessage(sender = 'noreply@example.com,
subject = 'CSV attached')
message.body = 'Download attached CSV' # only a text body
message.attachments = [blob_info.filename,blob_reader.read()]
message.send()
我看不到任何发送您创建的消息的方法,它是否在代码的另一部分?如果是,你也能分享吗?