JavaMail で単純な html メッセージを送信する必要があります。そして、インターネットで説明付きの良い例を見つけようとしたとき、次の例ごとに私はますます腹を立てました.
これらのばかげた例にはすべて、コメントのみが異なるコピー アンド ペーストされた Java コードが含まれています。
誰も具体的な製品の宣伝をしたくないことは理解していますが、サーバーの構成が最も難しい部分です。それで、具体的なサーバー(たとえば、Kerio、または他のサーバー)の構成に関する本当に役立つ情報(Javaコードなし)を誰か教えてもらえますか?
私が今持っているのは次の例外です:
250 2.0.0 Reset state
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Relaying to <mymail@mycompany.com> denied (authentication required)
アップデート。これまでのすべてのテキストを単純に再構成すると、Windows と jdk しかないと想像してください。そして、Java プログラムを作成してマシン上で実行したいとします。そして、このプログラムは「Hello world!」を送信する必要があります。あなたのGmailアカウントに。手順をリストします。
UPD2. コードは次のとおりです。
Properties props = new Properties ();
props.setProperty ("mail.transport.protocol", "smtp");
props.setProperty ("mail.host", "smtp.gmail.com");
props.setProperty ("mail.user", "my_real_address_1@gmail.com");
props.setProperty ("mail.password", "password_from_email_above");
Session mailSession = Session.getDefaultInstance (props, null);
mailSession.setDebug (true);
Transport transport = mailSession.getTransport ();
MimeMessage message = new MimeMessage (mailSession);
message.setSubject ("HTML mail with images");
message.setFrom (new InternetAddress ("my_real_address_1@gmail.com"));
message.setContent ("<h1>Hello world</h1>", "text/html");
message.addRecipient (Message.RecipientType.TO,
new InternetAddress ("my_real_address_2@gmail.com"));
transport.connect ();
transport.sendMessage (message,
message.getRecipients (Message.RecipientType.TO));
例外は次のとおりです。
RSET
250 2.1.5 Flushed 3sm23455365fge.10
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. 3sm23455365fge.10
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1368)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:886)
at com.teamdev.imgmail.MailSender.main(MailSender.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
...