当我试图从“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” 这是工作精细。
你确定“teja”是一个有效的域名吗? – mhasan
@mhasan .... teja是本地主机的名称,我试图从godaddy邮件服务器发送它。但它试图从本地主机发送它。 – Teja
你是如何设定电子邮件的来源? – Jeremy