I have a problem where a piece of code in java sends emails just fine except to public emails like Yahoo & Gmail.
Here are the headers for the email I receive when sent to my company email address:
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
Here's the java code:
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));
Is there anything that jumps out at you that maybe missing from the headers?