Friday, 12 August 2011

SubEthaSMTP: Store email as files before sending out

I have written a simple handler for SubEthaSMTP that will save emails to specific folders before sending them out. First the main function to setup stuff (SMTPServer.java)

You can download it from here. (Note: There are three source class in there, with their Class Name properly highlighted).

What it does is to start an SMTP server (standard SMTP Port) in the workstation/server you are running it on.

You will need to configure SMTPMessageHandlerFactory to set the appropriate smtp host, smtp port, smtp user and smtp password to send the email to.

Whenever a mail is received, it will write the contents of the mail in folder: outbox/{fromemailaddr}/{date}/{time}

It will work for normal mail (HTML/plain) and mail with attachments, but not message/rfc822 type.

Also, because I am not able to read BCC headers from the mail received via SMTP, instead of processing the TO, CC, and BCC in the mail content, I will send out the mail to everyone separately, putting them in the TO field for each email sent.

Please help to test out and comment accordingly. Thanks.

1 comment:

  1. hey i using your code but it is creating hundreds folders of same attach file and message. how will i prevent it from creating not more than one folder

    ReplyDelete