2017-03-08 177 views
0

当我试图从“smtpout.asia.secureserver.net”发送邮件时,它从本地主机发送而不是“secureserver”主机。下面是代码:Javamail - 从本地主机而不是godaddy服务器发送

Properties props = new Properties();  
      props.put("mail.smtp.host","smtpout.asia.secureserver.net");  
      props.put("mail.smtp.socketFactory.class",  
         "javax.net.ssl.SSLSocketFactory");  
      props.put("mail.smtp.auth", "true");  
      props.put("mail.smtp.port", "465"); 
      props.put("mail.smtp.starttls.enable","true"); 
      props.put("mail.debug", "true"); 

Session session = Session.getDefaultInstance(props,  
     new javax.mail.Authenticator() {  
     protected PasswordAuthentication getPasswordAuthentication() {  
     return new PasswordAuthentication("[email protected]","xxxxx"); 
     }  
     });  
     //compose message  
     try {  
     MimeMessage message = new MimeMessage(session);  
     message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));  
     message.setSubject(sub);  
     message.setText(msg);  
     //send message 
     Transport.send(message);  
     System.out.println("message sent successfully");  
     } 

赶上(MessagingException五){抛出新的RuntimeException(E);}

调试:

com.sun.mail.smtp.SMTPSendFailedException 
    550 <[email protected]> Sender Rejected - MAILFROM must be a valid domain. Ensure the mailfrom domain: "teja" has a valid MX or A record. 
    DEBUG SMTP: got response code 550, with response: 550 <[email protected]> Sender Rejected - MAILFROM must be a valid domain. Ensure the mailfrom domain: "teja" has a valid MX or A record. 

但是,如果我改变主机 “smtp.gmail.com” 这是工作精细。

+0

你确定“teja”是一个有效的域名吗? – mhasan

+0

@mhasan .... teja是本地主机的名称,我试图从godaddy邮件服务器发送它。但它试图从本地主机发送它。 – Teja

+0

你是如何设定电子邮件的来源? – Jeremy

回答

0

更改Java邮件罐子V1.5 +并添加无效javax.mail.internet.MimeMessage.setFrom(字符串地址)功能

0

它从本地主机发送,因为你做的大部分common JavaMail mistakes的。

MAILFROM问题是因为主机名称或名称服务在您的计算机上配置错误。作为解决方法,您可以设置mail.smtp.localhost属性。

相关问题