使用java发送Hotmail邮件。我收到了554.5.2.252错误。
我在线程"main"com.sun.mail.smtp.SMTPSendFailedException: 554 5.2.252…从我的hotmail帐户发送邮件时出错。
package utilities;
import java.io.IOException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class SecureEmail
{
//SETUP MAIL SERVER PROPERTIES
//DRAFT AN EMAIL
//SEND EMAIL
Session newSession = null;
MimeMessage mimeMessage = null;
public static void main(String args[]) throws AddressException, MessagingException, IOException
{
SecureEmail mail = new SecureEmail();
mail.setupServerProperties();
mail.draftEmail();
mail.sendEmail();
}
private void sendEmail() throws MessagingException {
String fromUser = "sansalnuray@hotmail.com";
String fromUserPassword = "***";
String emailHost = "smtp.office365.com";
Transport transport = newSession.getTransport("smtp");
transport.connect(emailHost, fromUser, fromUserPassword);
transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
transport.close();
System.out.println("Email successfully sent!!!");
}
private MimeMessage draftEmail() throws AddressException, MessagingException, IOException {
String[] emailReceipients = {"sansalnuray@gmail.com"};
String emailSubject = "Test Mail";
String emailBody = "Test Body of my email";
mimeMessage = new MimeMessage(newSession);
for (int i =0 ;i<emailReceipients.length;i++)
{
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(emailReceipients[i]));
}
mimeMessage.setSubject(emailSubject);
MimeBodyPart bodyPart = new MimeBodyPart();
bodyPart.setContent(emailBody,"html/text");
MimeMultipart multiPart = new MimeMultipart();
multiPart.addBodyPart(bodyPart);
mimeMessage.setContent(multiPart);
return mimeMessage;
}
private void setupServerProperties() {
Properties properties = System.getProperties();
properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
newSession = Session.getDefaultInstance(properties,null);
}
}
我的完整错误信息。
线程"main"5.2.252 SendAsDenied;sansalnuray@hotmail.com不允许发送为Sansal@SansalPC.mshome.net;STOREDRV.Submission.Exception: SendAsDeniedException.MapiExceptionSendAsDenied;处理消息失败,因为消息[BeginDiagnosticData]有永久异常。0.35250:1F00BE88, 1.36674:0A000000, 1.612500:00000000, 1.45378:02000000, 1.44866:0D020000,....
看起来您试图使用的电子邮件地址,不允许以Sansal@SansalPC.mshome.net的名义发送电子邮件,根据您给出的错误消息判断。这意味着一个"发送"限制已到位,并阻止您使用其他地址从此电子邮件地址发送电子邮件。
您必须确保您尝试发送的电子邮件地址是被授权发送电子邮件的电子邮件地址。