2017-09-14 13 views
1

通知メールを送信するアプリケーションを開発しています。その機能を導入する前にメールのエンドツーエンドテストを実施したいと思います。この目的のために、自分の開発マシンでダミーSMTPサービスを実行しています。これは、受信メールを受け取り、送信者と受信者が誰であろうと、POPクライアントがアクセスできる単一のボックスに格納します。私は他のアプリケーションでこれを使用して、電子メールが送信され、さまざまなクライアントが読み取り可能であることを確認しました。私は、デフォルトで、アプリケーションコードがメッセージを送信するために呼び出すことができるcom.google.appengine.api.mail.MailServiceがあり、実際の環境では実際に電子メールを送信することがわかります。しかし、開発環境では、メールが床に落ちているようです。Google App Engineのデベロッパーサーバーでテストメールを送信

Sep 13, 2017 9:05:38 PM com.google.appengine.api.mail.dev.LocalMailService log 
INFO: MailService.send 
Sep 13, 2017 9:05:38 PM com.google.appengine.api.mail.dev.LocalMailService log 
INFO: From: myapp <[email protected]> 
Sep 13, 2017 9:05:38 PM com.google.appengine.api.mail.dev.LocalMailService log 
INFO: To: Recipient <[email protected]> 
Sep 13, 2017 9:05:38 PM com.google.appengine.api.mail.dev.LocalMailService log 
INFO: Reply-to: myapp <[email protected]> 
Sep 13, 2017 9:05:38 PM com.google.appengine.api.mail.dev.LocalMailService log 
INFO: Subject: Email Update 
Sep 13, 2017 9:05:38 PM com.google.appengine.api.mail.dev.LocalMailService log 
INFO: Body: 
Sep 13, 2017 9:05:38 PM com.google.appengine.api.mail.dev.LocalMailService log 
INFO:  Content-type: text/plain 
Sep 13, 2017 9:05:38 PM com.google.appengine.api.mail.dev.LocalMailService log 
INFO:  Data length: 948 

しかし、私は、実際のメッセージを表示させるための明確な方法があるように思えません。私はこのようなワーカースレッドからログメッセージを参照してください。私はこのコードのビット書くために私を導いたのGoogleドキュメントの例見つけた:私は私のdevのサーバーでこれを実行すると、しかし

Properties mailProps = new Properties(); 
    AbstractConfiguration config = ConfigurationManager.getConfig(); 
    String smtpHost = config.getString("email.smtp.host"); 
    __l.debug("Sending email via SMTP connection to host "+smtpHost); 
    mailProps.setProperty("mail.smtp.host", smtpHost); 
    mailProps.setProperty("mail.smtp.port", config.getString("email.smtp.port", "25")); 
    mailProps.setProperty("mail.smtp.connectiontimeout", config.getString("email.smtp.connectiontimeout", "1000")); 
    mailProps.setProperty("mail.smtp.timeout", config.getString("email.smtp.timeout", "1000")); 
    Session session = Session.getDefaultInstance(mailProps, null); 
    try { 
     Message msg = new MimeMessage(session); 
     msg.setFrom(new InternetAddress(config.getString("email.sender.address"), config.getString("email.sender.name"))); 
     msg.addRecipient(Message.RecipientType.TO, 
         new InternetAddress(toAddress, toName)); 
     msg.setSubject(title); 
     msg.setText(messageText); 
     Transport.send(msg); 
     __l.info("message has been sent to " + toAddress); 
    } catch (Exception e) { 
     __l.warn("Exception attempting to send email to "+toAddress+" about "+title, e); 
    } 

を、それは私がまだに建て使用しているように見えますMailServiceと私のローカルダミーSMTPサービスは実際には接触しません。電子メールクライアントでアプリ生成電子メールを表示できるという私の目標を達成するための方法はありますか?「大きなラボ」で新しいメールテンプレートをすべてデバッグするだけですか?

答えて

0

sendmailまたはローカルSMTPサーバーを使用するように開発サーバーを構成していない場合、動作が期待されます。 Mail and the development serverから:

開発サーバーを使用すると、 は、メッセージを送信し、あなたのアプリの機能をテストするときには、コンピュータから直接電子メールメッセージ を送信するように設定することができます。選択した SMTPサーバーを使用するように開発サーバーを構成できます。 Sendmailが コンピュータにインストールされていて、電子メールを送信するように設定されている場合は、 開発サーバーにSendmailを使用するように指示することもできます。

アプリがメールサービスを呼び出すときにSMTPサーバーを構成しない、またはSendmailを有効にしないと、開発サーバーはメッセージの内容を として記録します。メッセージは実際に送信されません。

のsendmailまたは特定のSMTPサーバーを使用するようにローカルの開発サーバーを設定するためのオプションがLocal Development Server Optionsに記載されています:

--enable_sendmail=yes|no 
    Uses the local computer's Sendmail installation for sending email messages. 

...

--smtp_host=... 
    The hostname of the SMTP server to use for sending email messages. 
--smtp_port=... 
    The port number of the SMTP server to use for sending email messages. 
--smtp_user=... 
    The username to use with the SMTP server for sending email messages. 
--smtp_password=... 
    The password to use with the SMTP server for sending email messages. 

更新:

@Stephen Bが指摘したように上記のみのpythonのサンドボックスに適用され、JavaのMail and the development serverだけです:

開発サーバーで実行中のアプリケーションがメッセージ、電子メールメッセージを送信するためにメール サービスを呼び出すとアプリケーションログの に出力されます。開発サーバーは電子メールを送信しません メッセージ。

+0

これはPythonで動作する可能性がありますが、実際にはJava開発環境では役に立ちません。 –

+0

うん、そうだよ。 –

関連する問題