我有一个问题,即java中的一段代码发送电子邮件就好了,除了雅虎和电子邮件等公共电子邮件。的Gmail。
以下是我发送到公司电子邮件地址时收到的电子邮件的标题:
Date: Wed, 30 Apr 2014 10:56:05 -0400
From: <test@mycompany.com>
To: <testmycompany@gmail.com>
Message-ID: <743410318.7.1398869765575.JavaMail.test@test-win7>
Subject: Order Attached
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_6_255846116.1398869765268"
Return-Path: test@mycompany.com
X-MS-Exchange-Organization-AuthSource: S1P5HUB7.EXCHPROD.USA.NET
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AVStamp-Mailbox: SMEXtG}w;1076300;0;This mail has
been scanned by Trend Micro ScanMail for Microsoft Exchange;
X-MS-Exchange-Organization-SCL: 0
X-EsetId: B021473D1D017139E26C16
这是java代码:
MimeMessage msg = new MimeMessage(mailSession);
msg.setHeader("Content-Type", getContentType(email.getContentType()));
msg.setFrom(getInternetAddress((email.getFrom() == null || email.getFrom().getEmail() == null) ? new EmailAddress(emailConfiguration.getDefaultFromEmail()) : email.getFrom()));
msg.setRecipients(Message.RecipientType.TO, getRecipientArray(email.getRecipients()));
msg.setSubject(email.getSubject(), getContentType(email.getContentType()));
msg.setSentDate(new Date());
if (email.getAttachments() == null || email.getAttachments().size() == 0) {
msg.setContent(new String(email.getBody()), getContentType(email.getContentType()));
} else {
MimeMultipart body = new MimeMultipart();
email.setBody("This is a new Vendor Order.\nPlease respond.");
if (email.getBody() != null && email.getBody().length > 0) {
MimeBodyPart textPart = new MimeBodyPart();
textPart.setContent(new String(email.getBody()), getContentType(email.getContentType()));
body.addBodyPart(textPart);
}
for (EmailAttachment attachment: email.getAttachments()) {
MimeBodyPart part = new MimeBodyPart();
InMemoryDataSource fds = new InMemoryDataSource(attachment);
part.setDataHandler(new DataHandler(fds));
part.setFileName(fds.getName());
body.addBodyPart(part);
}
msg.setContent(body);
}
transport = mailSession.getTransport(msg.getFrom()[0]);
Socket socket = new Socket(emailConfiguration.getMailHost(), emailConfiguration.getMailPort());
socket.setSoTimeout(emailConfiguration.getIdleTimeoutInSeconds() * 1000);
if (connectionListener != null) {
connectionListener.setSocket(socket);
}
((SMTPTransport)transport).connect(socket);
transport.sendMessage(msg, msg.getRecipients(Message.RecipientType.TO));
标题中是否有任何跳出来的东西可能会丢失?
答案 0 :(得分:0)
您应该检查邮件服务器的响应。我尝试连接到gmail服务器一次以检查是否存在邮件地址,但它没有工作,因为我的ISP的ip块被列入黑名单以避免来自受感染家庭计算机的垃圾邮件。我忘记了链接,但有一个网站,你可以检查你的IP是否被列入黑名单。