Could not connect to SMTP host: smtp.sina.com, port: 25
1617 ワード
1.メール設定でPOP 3/SMTPサービスをオンにする.
2.ウイルス対策ソフトやファイアウォールをインストールしている場合、たとえば、McAFeeはコンソール→アクセス保護(右ボタン)→プロパティ→ウイルス対策標準保護→群発メールワーム送信禁止→前にフックがない
コードは次のとおりです.
2.ウイルス対策ソフトやファイアウォールをインストールしている場合、たとえば、McAFeeはコンソール→アクセス保護(右ボタン)→プロパティ→ウイルス対策標準保護→群発メールワーム送信禁止→前にフックがない
コードは次のとおりです.
public boolean send(String to_mail_address,String subject,String content){
try {
String from_mail_address = userName;
Authenticator auth = new PopupAuthenticator(userName, password);
Properties mailProps = new Properties();
mailProps.put("mail.smtp.host", smtp_server);
mailProps.put("mail.smtp.auth", "true");
mailProps.put("username", userName);
mailProps.put("password", password);
Session mailSession = Session.getDefaultInstance(mailProps, auth);
mailSession.setDebug(true);
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from_mail_address));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(
to_mail_address));
message.setSubject(subject);
MimeMultipart multi = new MimeMultipart();
BodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setText(content);
multi.addBodyPart(textBodyPart);
message.setContent(multi);
message.saveChanges();
Transport.send(message);
return true;
} catch (Exception ex) {
System.err.println(" :" + ex.getMessage());
System.err.println(" ");
ex.printStackTrace(System.err);
return false;
}
}