java - Sending test emails with Google AppEngine dev server -
i'm developing application send out notification emails , i'd perform end-to-end testing on email before deploy capability. end, i've got dummy smtp service running on development machine accepts incoming mail , stores in single box pop client can access, no matter sender , receiver are. i've used other applications make sure emails sent, they're readable various clients, , on. see that, default, there com.google.appengine.api.mail.mailservice application code can call send messages and, in real environment, sends email. however, in dev environment, mail seems dropped on floor. see log messages worker threads this:
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 <myapp-sender@myapp.appspotmail.com> sep 13, 2017 9:05:38 pm com.google.appengine.api.mail.dev.localmailservice log info: to: recipient <user@test.com> sep 13, 2017 9:05:38 pm com.google.appengine.api.mail.dev.localmailservice log info: reply-to: myapp <myapp-sender@myapp.appspotmail.com> 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
but there doesn't seem obvious way me see actual message. did find example in google documentation led me write bit of code:
properties mailprops = new properties(); abstractconfiguration config = configurationmanager.getconfig(); string smtphost = config.getstring("email.smtp.host"); __l.debug("sending email via smtp connection 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 " + toaddress); } catch (exception e) { __l.warn("exception attempting send email "+toaddress+" "+title, e); }
however, when run in dev server, looks i'm still using built in mailservice, , local dummy smtp service never gets contacted. there way achieve goal of being able view app-generated email in email client, or debug every new email template in "the big lab"?
the behaviour expected if didn't configure development server use sendmail or local smtp server. mail , development server:
the development server can configured send email messages directly computer when test feature of app sends messages. can configure development server use smtp server of choice. alternatively, can tell development server use sendmail, if sendmail installed on computer , set sending email.
if not configure smtp server or enable sendmail, when app calls mail service, development server log contents of message. message not sent.
the options configuring local development server use sendmail or specific smtp server documented in local development server options:
--enable_sendmail=yes|no uses local computer's sendmail installation sending email messages.
...
--smtp_host=... hostname of smtp server use sending email messages. --smtp_port=... port number of smtp server use sending email messages. --smtp_user=... username use smtp server sending email messages. --smtp_password=... password use smtp server sending email messages.
update:
as @stephen b noted above applies python sandbox, java mail , development server just:
when application running in development server calls mail service send email message, message printed application logs. development server not send email message.
Comments
Post a Comment