I'm using javamail to send mails from my appengine application. It works perfectly in the deployment, but I can't figure out how to do this using the development server. Whenever I need to test the sendmail, I'm having to deploy the application which is quite annoying.
Background Information (Why logs don't work):
We know emails go to the logs on the appengine development server. However, the primary reason for wanting to send emails from the development server is to be able to test the format of the email. How does it look? Do changes need to be made to the email template so it looks good in email clients A, B, and C, and can it be done quickly without the hassle of deploying to a real, default appengine version each and every time.
We're not spammers. We're not trying to circumvent any type of security. In short, we want to legitimately be able to see the real, actual email in one or more email clients and then make code changes instantly so we can tweak them without having to go through the painstaking process of the edit, compile, wait 5 minutes for it to deploy, test, repeat cycle. Since there are no standards in how each email client renders an email, this painstaking process is amplified by trying to get something to work in many clients.
Question:
How can the Java Google App Engine Development server be configured to send emails from the local computer or an SMTP service for the purpose of testing emails sent to real, actual email clients?
In case anyone else stumbles across this question, here are the instructions for configuring your local GAE server to send mail
You can do the following for setting up email on the development server
And use the session normally to send emails:
Additionally you need to add the following two libraries in build path and under war/WEB-INF/lib:
You can find the links easily by googling them.
Finally if you want to use gmail as the smtp server, you need to go to your account, and enable access for less seucre apps https://www.google.com/settings/security/lesssecureapps
GAE uses JavaMail, so it's not too difficult to get it working. There are two things you'll need to change.
The first is to set up your JavaMail session properly for your STMP server. To do this, instead of using
Session.getDefaultInstance
, useSession.getInstance
, providing at least themail.smtp.host
properties. See JavaMail SMTP reference, or just look for a generic JavaMail SMTP tutortial.The second change is that you need to stop GAE handling your emails. It does this because of the line
in META-INF/javamail.address.map in the SDK jar. You can either include your own address map - but that is annoying because I assume you only want it for debugging - or modify the address map from code. That is as simple as doing
on the session you created in the first step. That should route all your emails to the standard SMTP handler.
From Eclipse, select the Run menu, Debug Configurations..., and then select your app’s configuration. Select the Arguments tab, then in the “VM arguments” section, set VM properties like this:
-Dmail.log_mail_level=WARNING -Dmail.log_mail_body=true
When I worked with an e-mail service implementation I used a cool hint. So if you use
MimeMessage
too, and want just check if the message is formatted as expected, checking if attachments are there, HTML is well formatted, images are right referenced and so on, you could build the entire message, and during debug you could have some code like this:Every time this is executed the
MimeMessage
instane will be saved toemailSent.eml
. This file you can open with your e-mail reader and check if everything is fine.Of course that you need to execute your application with -Dmail.debug=1 parameter.
An example with attached file, text message and html message with this approach could be like this:
From the docs:
So just check the logs when you intend to send mail, and make sure that it shows up there. No real mail will actually get sent.