Does anybody know the smtp settings that need to be applied within the application.conf file of a Play Framework project for sending emails on localhost?
During my unit testing I am getting the error:
A play.exceptions.MailException has been caught, Cannot send email
The developers at Play have made sending emails so easy that the only way I could be messing up is with my settings in the config file.
I have tried just using:
mail.smtp=mock
And I tried commenting out the line above and using:
mail.smtp.host=127.0.0.1
Neither of these two approaches work. I understand that this is probably a very noob question, but I have never really dealt with setting up emails before - so I am grateful for any help that can be contributed.
If it is the case that I am unable to send email as Play would not work as an SMTP server, is there any way that I can use mail.smtp=mock to 'mock send' an email and allow my tests to pass?
Useful Link
This is a link to the Play documentation for sending emails
To better diagnose the problem, you can use the following setting (in application.conf) to give more details of the email sending process.
mail.debug=true
However, for testing purposes, I have found using GMail the easiest method for sending emails.
The configuration (again in application.conf) is...
mail.smtp.host=smtp.gmail.com
mail.smtp.user=yourGmailLogin
mail.smtp.pass=yourGmailPassword
mail.smtp.channel=ssl
For full details of all the configurations, the Play Framework page has lots of information on how to do this.
http://www.playframework.org/documentation/1.2.2/emails
I use 1.2.4. (haven't ported yet...)
There are various reasons why play.mvc.Mailer.send() may fail, however the true reason is suppressed if you look at the first level of the exception thrown since what gets thrown is (play.mvc.Mailer.java:349):
throw new MailException("Cannot send email", ex);
play.exceptions.MailException inherits from java.lang.RuntimeException. The real exception, ex, is set as the cause.
I'd recommend taking a look at the cause field. Example:
try {
Future<Boolean> future = play.mvc.Mailer.send(...);
} catch(MailException me) {
System.out.println(me.getCause().getMessage());
}
This may print out something more useful.
For future developers I use Play2.1 on Mac OSX, this is my mail configuration to send to localhost...
host=localhost
port=1025
user="root#localhost"
from="root#localhost"
using MockSMTP application available at the Mac store http://mocksmtpapp.com/
Also using typesafe plugin
https://github.com/typesafehub/play-plugins/tree/master/mailer
I hope this can help someone in the future.
Related
I'm working on a project I'm Java with regards to outlook.
Here I'm able to do all the functions like Read a mail, write a mail, reply to a mail etc...
But now we've been thinking of taking it to the next level.
Our plan is as below.
We have an email address like info#myDomain.com, when ever an email is sent to this address, I need to reply them. Here basically customers send an email asking for some data, and we've the data available in our portal, and we just need to send it.
The response would be Like thank you for contacting us, we will get back to you soon. Mean while please look into this {URL}.
And this has to be done automatically when ever there is an email hit to this particular email address.
Couple of questions:
- should my machine be on the whole day to get this thing done.
- is there a way that a Java application can automatically monitor my inbox to see for this case match.
- Also, can I have this running in the bg.
Can someone please point me into the right direction/approach where can I can start working on this task.
Thanks
when ever an email is sent to this address, I need to reply them.
For this you need to monitor your email account fro incoming emails. Here is one of the way to do this
The response would be Like thank you for contacting us, we will get back to you soon. Mean while please look into this {URL}.
Once you receive an email (using above email monitoring approach), you need to call a method that sends the reply with above format
And this has to be done automatically when ever there is an email hit to this particular email address.
Above two steps accomplishes this task.
should my machine be on the whole day to get this thing done
Basically, you will need an application server (like tomcat) where your above java program is deployed. So, yes this server needs to be running and available all the time.
is there a way that a Java application can automatically monitor my inbox to see for this case match
Check point 1
Also, can I have this running in the bg
You can run tomcat as a service in windows (more info). It has many advantages, automatic startup on boot being the one. Similar implementations are also available for other OS.
So, in short, this can be accomplished. It is bit complex but not much difficult. Cheers
I have an alpha staged program with many bugs, and I would like to let people send their logs on a server (mail, git, etc...) so i can look them up and fix them. I have searched allot on this topic and I haven't found a way to do it without downloading a git full of logs, or needing an authentication for a mail or a dedicated server.
Is there a way to make my Java program send automatically its error log on a server when it crashes, without needing costly hardware or authentification? (i have a 0$ budget).
A free Loggly account sounds perfect for your needs.
You could use the javamail library to send emails to an account where you want to get the errorlogs. This wouldn't cost anything. And is very fast to implement/integrate in your project.
I would suggest to create a new gmail account which will send the emails to your account, where you want to recieve and debug it.
I have a running and working implementation of the Java Mail API. I am using the api to send out bulk email messages. On some occasions, the login gets blocked by google. So, I go to my gmail account and allow access to apps and set the security level to give access to apps that don't use what google calls "modern security". So, the google page tells me to try my program again. I try it again and it still won't let me log in. On some occasions when I have a login fail, I can go to the account, log in, and type in the recaptcha. This will allow me to log back in shortly after and send emails. However, the problem I am now experiencing does not show any recaptcha, nor does it say anything about any unknown apps that tried to access the account. It says nothing, and just wont let me log in to my account. I created two new accounts for testing and they worked fine. The account that I created that doesn't work only allowed me to send 17 emails before it blocked my service. Does anyone have any suggestions? Thanks!
Go to your Gmail account setting page and Enable access of Less secure apps. Then try with Java Mail API. Hope it works for you.
Make sure that your JavaMail with google auth is working fine, Check concurrently with Different app. If not post your code
If you're using a free Gmail account, Google might think your bulk email is spam (duh). If you're going to send bulk email, it may be time to pay someone for a business account that will let you do that.
I'm trying to find an example on how to implement a Java client (using javamail perhaps) that retrieves emails from postfix, but unfortunately I haven't found anything usable in 8 hours.
I already managed to make an smtp client to send email to my postfix server running on localhost but still no success on getting that mail I sent back. With the imap client I always get some problems with the store and get connection refused.
Any suggestion?
Did you find the JavaMail FAQ? There's lots of tips there, including tips on how to debug and what additional information we would need to see to help you figure out what's wrong. So far all you've told us is that something's not working. Without more details, we can't offer more than general suggestions.
I'm writing a program, that sends email messages and want to know when the receiver receives the email message I've sent to him. How can I do this using JavaMail API?
If I use SMTPMessage, how exactly to deal with the result after I've set the notify options?
SMTPMessage smtpMsg = new SMTPMessage(msg);
smtpMsg.setNotifyOptions(SMTPMessage.NOTIFY_SUCCESS);
There is no standard way of doing this that's accepted and honored across the board. I see that you have some options, though:
Add a header "Return-Receipt-To" with your e-mail address in the value. If the recipient of the e-mail has a client which honors this header, then a return receipt will be sent to you when the e-mail is opened. This is not reliable, mind you, as the user can always decide not to send the receipt, even if he has a client that supports it.
Add an image into your e-mail that loads from your server and put a parameter on the image that includes the user's e-mail address. When the e-mail loads, the image will load from your server. Write a script that collects the e-mail parameter and then delivers a blank image. This is also not reliable, however, as many mail clients prompt users if they wish to download images and they can always choose not to. Also, some (mostly older) e-mail clients do not support images.
Perhaps the most reliable way is not to include the message in your e-mail at all. Include only a link to a website where the message can be read, and include their e-mail address or a unique code in the link. This way, you know exactly who read the message. Of course, this has the downside that people aren't actually getting the message in their inbox, and they also may choose not to go to the website to read it.
Ultimately, I think you're going to have to come up with a creative solution to solve this problem, unless you're happy getting spotty results.
Ok, this is an old discussion, but:
I've found a simple and working solution here (link in spanish).
You just need to add one more field to the header of the message. To achieve this you must use method addHeader of Part class, implemented by Message class. This method receives 2 parameters, type and value of header.
To get confirmation you must add this header:
Disposition-Notification-To
And the value is the mail where we want to send the confirmation answer:
message.addHeader("Disposition-Notification-To","mail#example.com");
ATTENTION: be aware that, nowadays, a lot of mail servers like gmail are discarding this requests, so this will not have effect, but, if you are sure (like me) receiver server allows this, will work like a charm.
please see my answer here (when this questioned was asked about ruby on rails). Tis basically the same answer.
Email open notification - ruby on rails
There is another approach to finding out whether an email has been received or not, it's getting undelivered emails. I've seen a rather good Java implementation here.
They used javax.mail (for mail processing) and guava (for processing strings and collections).
Just add a dummy image with display set to none in your message.And set the src attribute of this image to the url you want to call
You can use SMTP message and request for a delivery status (I don't know if it's coming when the provider receive the mail or if it's when the user open the mail).
JavaMail don't support directly these feature directly and you have to read the RFC 3464.
I also find this thread with examples but didn't try it javamail
You can also look at websina