Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending email with Javamail via imap

The convention with using JavaMail seems to be: -- Use smtp for sending emails -- Use imap (or pop) for reading emails ..

For our applications purposes, I reckon it is more useful to use an email client protocol (imap specifically) to send emails .. and ensure copies of all sent mail make into the 'Sent' folder of gmail or whatever mail account used.

Note, the primary point of the email connection is just to send mails, not to read or poll emails.

Would like opinions/suggestions/examples from others who have used imap for sending emails from their java apps. All posts appreciated.

like image 608
Chux Uzoeto Avatar asked Apr 05 '12 16:04

Chux Uzoeto


People also ask

Which protocol is used to receive the messages in JavaMail?

IMAP. IMAP is an acronym for Internet Message Access Protocol. IMAP is an advanced protocol for receiving messages. It provides support for multiple mail box for each user ,in addition to, mailbox can be shared by multiple users.

How do you write a program to implement send and receive the e mails?

Sending Email With Attachments Create a new session object. Create a MimeBodyPart object and assign text to it. Create a new MimeBodyPart object and assign DataHandler object to it. Create a MultiPart object and assign the two MimeBodyPart objects to this MultiPart Object.


1 Answers

Simple answer: It is not possible to send emails with IMAP. You have to use SMTP for sending emails.

More precisely there are some extensions to combine sending and retrieval operations. However, as far as I know, these extensions are not widely spread - neither on the client nor on the server side.

See also the article on wikipedia about IMAP (IMAP#Disadvantages):

Unlike some proprietary protocols which combine sending and retrieval operations, sending a message and saving a copy in a server-side folder with a base-level IMAP client requires transmitting the message content twice, once to SMTP for delivery and a second time to IMAP to store in a sent mail folder. This is remedied by a set of extensions ...

like image 91
nosid Avatar answered Oct 08 '22 10:10

nosid