[play-framework] Easy way to READ emails with Play! ? Code expl for POP or IMAP ? (I know it's easy to send by SMTP on GMail accounts)

358 views
Skip to first unread message

Dam74

unread,
May 4, 2010, 6:02:27 AM5/4/10
to play-framework

Hi,

I manage to send mails by the following SMTP config with Play.

mail.smtp.host=smtp.gmail.com
mail.smtp.port=465
mail.smtp.channel=ssl
mail.smtp.user=MyAc...@gmail.com
mail.smtp.pass=MyPassword

From what I have read, SMTP is only done to send, not to READ mails
from the Inbox.
Does Play provide an easy way to READ mails, and change their status
("is read" <=> "is not read") or even in which folder they are ?

If not, should I try by POP3 or IMAP ? Any opinion on what is the
easiest ?
Any code from anyone ?

Thanks

Dam74

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Ivan Meredith

unread,
May 4, 2010, 7:21:04 AM5/4/10
to play-fr...@googlegroups.com
Have a look at javamail.
http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailFetching

I have used it for pop/imap quite a bit.

You have to follow imap conventions if you want to look in folders.
You have to open a folder, check to see if the message is there etc.

Google has lots of results for example code, the API docs are also pretty good.

-Ivan

Erwan Loisant

unread,
May 4, 2010, 7:43:17 AM5/4/10
to play-fr...@googlegroups.com
Hi,

What are you trying to achieve? Do you need to manipulate a user's
inbox on a specific server (like gmail), or do you need to receive and
process automatically emails from users, for example to confirm an
account or upload a picture by email?

If it's the first one, indeed Ivan's proposal is probably good.

If it's the second one, usually receiving emails from a server is not
done with POP or IMAP but rather by having your own SMTP server that
receives the emails directly. Both POP and IMAP work by polling an
inbox, and polling sucks and should be avoided when possible. With
scripting languages like PHP you would configure
Sendmail/Qmail/whatever to call a script when an email
arrives. With Java, the best is to embed an SMTP server in your application.

I don't think there is such a feature in Play's core, but SubEtha SMTP
seems pretty popular (I haven't tried it though):
http://code.google.com/p/subethasmtp/

It's a lib that lets you start a server on application start, then you
can define handlers that get called when a new message arrives.
--
Erwan Loisant

Dam74

unread,
May 4, 2010, 11:07:51 AM5/4/10
to play-framework
Cool... That's indeed one of the tutorials I've found and used.
Thanks

On May 4, 1:21 pm, Ivan Meredith <i...@ivan.net.nz> wrote:
> Have a look at javamail.http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#J...
>
> I have used it for pop/imap quite a bit.
>
> You have to follow imap conventions if you want to look in folders.
> You have to open a folder, check to see if the message is there etc.
>
> Google has lots of results for example code, the API docs are also pretty good.
>
> -Ivan
>
>
>
> On Tue, May 4, 2010 at 10:02 PM, Dam74 <damienhur...@hotmail.com> wrote:
>
> >           Hi,
>
> > I manage to send mails by the following SMTP config with Play.
>
> > mail.smtp.host=smtp.gmail.com
> > mail.smtp.port=465
> > mail.smtp.channel=ssl
> > mail.smtp.user=MyAcco...@gmail.com
> > mail.smtp.pass=MyPassword
>
> > From what I have read, SMTP is only done to send, not to READ mails
> > from the Inbox.
> > Does Play provide an easy way to READ mails, and change their status
> > ("is read" <=> "is not read") or even in which folder they are ?
>
> > If not, should I try by POP3 or IMAP ? Any opinion on what is the
> > easiest ?
> > Any code from anyone ?
>
> > Thanks
>
> >             Dam74
>
> > --
> > You received this message because you are subscribed to the Google Groups "play-framework" group.
> > To post to this group, send email to play-fr...@googlegroups.com.
> > To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/play-framework?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/play-framework?hl=en.

Dam74

unread,
May 4, 2010, 11:16:39 AM5/4/10
to play-framework
My Java/Play application is currently hosted on "stax.net" and they do
not provide any mail solution.

I don't know anything about email programming...
I managed to read the mails of a GMail account by IMAP using JavaMail
as advised by Ivan.
But you're saying (and I think you are right) that polling regularly
(like every min) to the GMail account "sucks",
and that I might be banned from GMail if they detect it has harmfull.

But how can I do like you are suggesting ? :
"
> SubEtha SMTP seems pretty popular:http://code.google.com/p/subethasmtp/
> It's a lib that lets you start a server on application start, then you
> can define handlers that get called when a new message arrives.
"
=> can you explain that ? Where these new messages would arrive ?
In my GMail account ? or nothing to do anymore with any external mail
server
and this is a real self sufficient mail server ??


I do not have any Domain name for the moment...
So, even without one, Can I put in place a mail server within my
JavaApplication ?
Will this be able to send and, most important, RECEIVE mails ? If yes,
which would be the email address ? (what would it look like?)
I would really me interested in a deeper explanation of your proposal.

Thanks in advance.


Other solution than GMail, I'm investigating if http://sendgrid.com/
would provide any advantage compared to GMail...


Dam74


On May 4, 1:43 pm, Erwan Loisant <elois...@gmail.com> wrote:
> Hi,
>
> What are you trying to achieve? Do you need to manipulate a user's
> inbox on a specific server (like gmail), or do you need to receive and
> process automatically emails from users, for example to confirm an
> account or upload a picture by email?
>
> If it's the first one, indeed Ivan's proposal is probably good.
>
> If it's the second one, usually receiving emails from a server is not
> done with POP or IMAP but rather by having your own SMTP server that
> receives the emails directly. Both POP and IMAP work by polling an
> inbox, and polling sucks and should be avoided when possible. With
> scripting languages like PHP you would configure
> Sendmail/Qmail/whatever to call a script when an email
> arrives. With Java, the best is to embed an SMTP server in your application.
>
> I don't think there is such a feature in Play's core, but SubEtha SMTP
> seems pretty popular (I haven't tried it though):http://code.google.com/p/subethasmtp/
>
> It's a lib that lets you start a server on application start, then you
> can define handlers that get called when a new message arrives.
>
>
>
> On Tue, May 4, 2010 at 12:02, Dam74 <damienhur...@hotmail.com> wrote:
>
> >           Hi,
>
> > I manage to send mails by the following SMTP config with Play.
>
> > mail.smtp.host=smtp.gmail.com
> > mail.smtp.port=465
> > mail.smtp.channel=ssl
> > mail.smtp.user=MyAcco...@gmail.com
> > mail.smtp.pass=MyPassword
>
> > From what I have read, SMTP is only done to send, not to READ mails
> > from the Inbox.
> > Does Play provide an easy way to READ mails, and change their status
> > ("is read" <=> "is not read") or even in which folder they are ?
>
> > If not, should I try by POP3 or IMAP ? Any opinion on what is the
> > easiest ?
> > Any code from anyone ?
>
> > Thanks
>
> >             Dam74
>
> > --
> > You received this message because you are subscribed to the Google Groups "play-framework" group.
> > To post to this group, send email to play-fr...@googlegroups.com.
> > To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/play-framework?hl=en.

Erwan Loisant

unread,
May 4, 2010, 3:50:21 PM5/4/10
to Dam74, play-fr...@googlegroups.com
On Tue, May 4, 2010 at 18:04, Dam74 <damien...@hotmail.com> wrote:
> My Java/Play application is currently hosted on "stax.net" and they do
> not provide any mail solution.

You don't need them to provide any mail solution. What you do need is
to be able to listen on port 25, and since stax is servlet I don't
know whether it's possible or not.

Maybe your current workaround is the only way.

> I don't know anything about email programming...
> I managed to read the mails of a GMail account by IMAP using JavaMail
> as advised by Ivan.
> But you're saying (and I think you are right) that polling regularly
> (like every min) to the GMail account "sucks",
> and that I might be banned from GMail if they detect it has harmfull.

They probably won't ban you (as people could configure their email
client to check email every minute) but it's sub-optimal to have to
check at regular interval.

> But how can I do like you are suggesting ? :
> "
>> SubEtha SMTP seems pretty popular:http://code.google.com/p/subethasmtp/
>> It's a lib that lets you start a server on application start, then you
>> can define handlers that get called when a new message arrives.
>
> "
> => can you explain that ? Where these new messages would arrive ?
> In my GMail account ? or nothing to do anymore with any external mail
> server and this is a real self sufficient mail server ??
> I thought that SMTP was for SENDING only, not RECEIVING mails ? Is
> that right ?

You may think that by configuring an email client, but from a server
point of view SMTP is both for sending and receiving.

For example, when a Hotmail user sends an email to your gmail account,
Hotmail's SMTP sends the email to GMail's SMTP who stores it. Then you
can see it from the web interface of GMail, or retrieve it with POP
or IMAP. So GMail's SMTP is actually receiving the message.

When you have your own SMTP server, it gets messages directly from
other SMTP servers and you skip the part where the user fetch it
through POP or IMAP.

> I do not have any Domain name for the moment...
> So, even without one, Can I put in place a mail server within my
> JavaApplication ?
> Will this be able to send and, most important, RECEIVE mails ? If yes,
> which would be the email address ? (what would it look like?)
> I would really me interested in a deeper explanation of your proposal.

What you need is:
- A machine (physical or virtual) with a public IP address
- The possibility to listen on the port 25 of this machine

The right part of the email address would be the address of the
machine. It can be on a subdomain, with email like
con...@myservice.stax.net (if they provide these kind of subdomains).
You can also get a free domain on eu.org or dyndns.org and map it on
the IP you have. Anyway, domains are cheap now...

Again I don't know if you can listen on port 25 on stax, maybe it's
not possible.

> Thanks in advance.
>
> Other solution than GMail, I'm investigating if http://sendgrid.com/
> would provide any advantage compared to GMail...

It looks like something like mailchimp, to do mass mailing. First of
all it's to send email, not receive them, and the only benefit of
these services are:
* Be able to send a lot of emails in a short period of time
* Do so without being marked as spam
If you don't want to do a newsletter you probably don't need that.
Reply all
Reply to author
Forward
0 new messages