I\'m trying to use JavaMail to send email from an EC2 Ubuntu 12.04 Server but it\'s not working.
I intend to send an
In the past, spam sent from servers within EC2 has been a major problem for both Amazon and mail service providers. Initially, Amazon deliberately had insufficient DNS information to pass anti-spam checking of common email services (lack of DNS reverse lookup PTR records), then Amazon introduced low mail quotas, followed approval processes to give full access to EC2 or SES mail (provides specific technical setup to fully enable outgoing email).
Here's a link describing some of the history: http://shlomoswidler.com/2009/07/sending-email-from-ec2.html
While the error you're getting is a failed authentication at Gmail server, it may be (probably is) because Gmail identifies your sender IP address as a potential spammer, because you didn't setup Amazon reverse DNS lookup properties correctly.
Setup Amazon Reverse DNS lookup details, so that your mail is not detected as spam by Gmail. It seems this can only be done by submitting a request form to lift Email Sending quota. From Amazon EC2 IP Information FAQs:
Q: Can I configure the reverse DNS record for my Elastic IP address?
Yes, you can configure the reverse DNS record of your Elastic IP address (submit the Request to Remove Email Sending Limitations Form). Note that a corresponding forward DNS record pointing to that Elastic IP address must exist before we can create the reverse DNS record.
Here's an example of an email sent out by Amazon when an email quota is exhausted - again spelling out request & approval for DNS PTR configuration: http://www.practicalclouds.com/content/guide/sending-email-ec2-instances
Precisely follow all the instructions in the link included in you Gmail error message: http://support.google.com/mail/bin/answer.py?answer=14257. This will reset your Gmail account status, if Gmail thinks your account is spamming from your IP address.
Alternatively, you can send mail via Amazon SES, also requiring request, approval and appropriate Amazon-provided configuration. This allows mail to be sent via com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient.sendEmail
. If you use this, add authorisation for your code to sendmail: Unable to send email from Amazon EC2 Server in Java.