私は類似の問題を抱えているユーザーについてここで他の多くの記事を検索しましたが、うまくいかないようです。JavaMailを使用して仕事の電子メールサーバーにメールを送信
私は、Java 1.8を使用していますpackage testingstuff;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.Message.RecipientType;
import javax.mail.internet.*;
import javax.activation.*;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World");
final String user = "my work ID";
final String pw = "my work Password";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "server I got from our outlook app");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, pw);
}
});
session.setDebug(true);
try {
Message msg = new MimeMessage(session);
String from = "[email protected]";
String to = "[email protected]";
msg.setFrom(new InternetAddress(from));
msg.setRecipient(RecipientType.TO, new InternetAddress(to));
msg.setSubject("TEST");
msg.setText("TESTING");
//Transport trans = session.getTransport("smtp");
//trans.connect("smtp-mail.outlook.com", 25, user, pw);
Transport.send(msg);
}
catch (Exception e) {
System.out.println(e);
}
System.out.println("done");
}
}
、JavaMailのは、それがここでバージョン1.4.7
であることを報告したセッションのデバッグから出力された:
Hello World
DEBUG: setDebug: JavaMail version 1.4.7
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "[my work email server]", port 587, isSSL false
javax.mail.MessagingException: Could not connect to SMTP host: [my work email server], port: 587;
ネストされた例外は次のとおりです。
java.net.ConnectException: Connection timed out: connect
done
私が使っている電子メールサーバーは、outlook appからです。私はアカウント設定に行き、自分のアカウントと選択した変更を選択しました。これは電子メールの設定を含むウィンドウを開き、サーバーアドレスを含んでいます。
これまでやってみましたが、うまくいきませんでした。私は仕事のネットワークからそれを送信していたので、ブロックされていました。私はプライベートGmailや何かに電子メールを送信し、それが動作するかどうかを確認することをお勧めします –
おそらく、ポート番号は問題を引き起こす可能性があります。たとえば、 "80"を試してください。 – pilkington