简体   繁体   中英

send mail using java api

i have requirement that i need to send/receive email after successful login by user, upon click on email verification i will activate the user . i dont have dedicated smtp server for send/receive mails for this requirement. right now i am looking for free service for initial start up options , i gone through this http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/ for sending email through gmail. my question is can i receive mail using gmail smtp service?

Short answer: No, not with SMTP. But probably with IMAP/POP.

Long answer: SMTP is only used for sending email between MTAs (Mail Transfer Agent). You'll have to download the email from your email provider, google in this case, using IMAP or POP.

You'll have to connect and check regularly as without an MTA service on your end, you can't get email pushed to you. Most personal ISPs block outbound port 25 so setting up a MTA might be tricky as you have to figure out your providers SMTP relay (if they even have one!)

See here for enabling IMAP/POP support for gmail: https://support.google.com/mail/troubleshooter/1668960?hl=en

Google will find you a suitable imap/pop client library to use with java.

Edit:

If you are doing a regular e-mail verification step for a website registration, you don't need to receive an e-mail from the user. You send them an e-mail with aa link to your websites verification URL. The link contains a predetermined ID, say the sha1 sum of username + e-mail encoded into the URL. The user clicks the link and opens a specific page on your site where you verify the ID when the page is loaded. This is how it is usually done. This way you don't need to receive any email programmatically.

Unless receiving it by email is a specific requirement from your customer, in which case you can ignore this edit. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM