File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Aspirin Cannot Send Mails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Aspirin Cannot Send Mails" Watch "Aspirin Cannot Send Mails" New topic

Aspirin Cannot Send Mails

Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
I'm using the code below

In this case, I'm getting the exception below:

Whats going wrong here?
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3275

Well what the error message says! Your machine is not authorised to connect to the Google SMTP servers in this way, read the link they provide in the error message on how to resolve this.

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Google wrote:In order to prevent spam, Gmail refuses mail when the sending IP address does not match the sending domain. To send mail from your server to Gmail, we suggest using the SMTP relay provided by your ISP. Please note that we are unable to whitelist IP addresses or otherwise make exceptions at this time.

Hmmm! Seems like a very easy way to resolve this.
Marco Ehrentreich
best scout

Joined: Mar 07, 2007
Posts: 1294

Hi Treimin,

your problems with the Gmail server come down to the spam prevention mechanisms almost all SMTP servers on the internet are using today not just Gmail.

In order to prevent spammers from using a SMTP server as a relay for their spam mails almost every mail provider requires you to use SMTP authentication when sending mails. That means your mail program usually is configured to log in into a SMTP server with a username/password before it will be allowed to use this SMTP server.

It's not enough to have correct settings in the "from" or "to" field of an email because ALL data in an email can be spoofed and manipulated on its way through the internet. Neither the Gmail server nor any other professional SMTP server will trust you just because you have a valid "from" address in your mails!

If you're using an own, local SMTP server which sits between your host sending the emails and the Gmail server it's more likely that Gmail will accept the mails. BUT this local SMTP server should have a fixed IP address and a correctly set up DNS record (A record and reverse entry) so that Gmail is able to lookup and verify that this is a more or less trustworthy SMTP server. In this case it's still possible that you are using an IP range which is blacklisted.

For all this you have two practical solutions:

1.) If you have a fixed IP and access to configure DNS settings for it you could set up a SMTP relay which can be used by your application. Another advantage is that such a local mail relay can be used by all client applications in your network.
Then you would not send mails directly to the Gmail server but to your local mail relay. And the relaying SMTP server would forward your emails to the Gmail server. This would be an easy way for you because you wouldn't have to change anything in your code but the SMTP server (which should then point to your local relay). This is possible because it's relatively easy to set up a local SMTP server and simply allow any client from your local network to send mails without using authentication.

2.) You could send mails directly to the Gmail server but then you would have to use SMTP authentication/authorization in order to be allowed to send mails. You would have to use a valid Gmail account with username/password for your application to log in. Unfortunately - from what I read - Aspirin doesn't support authentication. It seems that it should just be used for simple applications in scenario 1.) and not for complex mail handling. In this case I think you will have to go for a more capable mail library like the JavaMail API.

I hope this explanations make the problem a little bit clearer for you ;-)

Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Many Thanks Marco, for your detailed instructions.

Please read this is what I really need to implement.
I agree. Here's the link:
subject: Aspirin Cannot Send Mails
jQuery in Action, 3rd edition