简体   繁体   English

从 Hotmail SMTP 发送电子邮件时出错

[英]Error While Sending Emails from Hotmail SMTP

Email Sending with Hotmail by using java.使用 java 使用 Hotmail 发送电子邮件。 I got 554.5.2.252 error.我收到 554.5.2.252 错误。

I got Exception in thread "main" com.sun.mail.smtp.SMTPSendFailedException: 554 5.2.252... error while sending emails from my hotmail account.我在线程“主”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);
    }
    
}   

My full error mesagge.我的完整错误信息。

Exception in thread "main" com.sun.mail.smtp.SMTPSendFailedException: 554 5.2.252 SendAsDenied;线程“主”com.sun.mail.smtp.SMTPSendFailedException 中的异常:554 5.2.252 SendAsDenied; sansalnuray@hotmail.com not allowed to send as Sansal@SansalPC.mshome.net; sansalnuray@hotmail.com 不允许发送为 Sansal@SansalPC.mshome.net; STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message [BeginDiagnosticData]Cannot submit message.由于消息 [BeginDiagnosticData] 无法提交消息的永久异常,无法处理消息。 0.35250:1F00BE88, 1.36674:0A000000, 1.61250:00000000, 1.45378:02000000, 1.44866:0D020000,.... 0.35250:1F00BE88、1.36674:0A000000、1.61250:00000000、1.45378:02000000、1.44866:0D020000、....

It looks like the email address you were trying to use, is not allowed to send an email under the name Sansal@SansalPC.mshome.net, judging by the error message you gave.从您提供的错误消息来看,您尝试使用的电子邮件地址似乎不允许以 Sansal@SansalPC.mshome.net 的名义发送电子邮件。 This means that a "Send As" restriction is in place and prevents you from sending emails from this email address using a different address.这意味着存在“发送为”限制,阻止您使用其他地址从此电子邮件地址发送电子邮件。

You must ensure that the email address you're trying to send from is one that is authorized to send emails.您必须确保您尝试发送的电子邮件地址是被授权发送电子邮件的地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM