「smtpout.asia.secureserver.net」からメールを送信しようとすると、「secureserver」ホストの代わりにlocalhostから送信されます。コードはJavamail - godaddyサーバーの代わりにlocalhostから送信
です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メールサーバーから送信しようとしています。しかし、localhostから送信しようとしています。 – Teja
電子メールの送信元はどのように設定していますか? thenew javax.mail.Authenticator(){たPasswordAuthentication(XXXXX @ xxxxx.net、パスワード)}で – Jeremy