Windows10で開発用のSMTPサーバを使いたい
環境
Windows10(VM)
設定
smtp4dev 2.0.9 standaloneをダウンロード
ダウンロードしたファイルを解凍して起動する
Windowsの機能が足りない場合は追加する
ファイアウォールを解除する
起動を確認
メール送信
JavaMailで送信する
package maven_test01; import java.util.Date; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class Sample01 { public static void main(String[] args) throws AddressException, MessagingException { Properties props = new Properties(); //smptサーバに関する設定 props.setProperty("mail.smtp.host", "localhost"); props.setProperty("mail.smtp.port", "25"); Session session = Session.getInstance(props, null); session.setDebug(true); MimeMessage msg = new MimeMessage(session); // 送信データ設定 msg.setFrom(new InternetAddress("test@example.com")); InternetAddress[] address = {new InternetAddress("hoge@example.com")}; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject("JavaMail APIs Test"); msg.setSentDate(new Date()); msg.setText("hogehoge"); // 送信 Transport.send(msg); } }