Email Forwarding

Jul 16, 2009 at 8:04 AM

hi,

Nice Work brother.

I have a question regarding the forwarding of a mime email using the code that you have written. Here is a bit of background of what I am trying to do and maybe you could comment on it:

I have created a windows service application to check pop3 mailbox every 60 seconds for email. The application will download an email check the originating address, save the attachments (if any) to disk and then forward the email to some other email address.  One way of forwarding is to make a new smtpMessage, copy all the data (email address, body, attachement etc) and send it using smtpClient, which i think is not the most appropiate way as it might loose some meta data. What i need is to just forward the email without loosing any data. Can you suggest any other, best way of doing it.

Any comment would be much appreciated.

Best Regards,

Coordinator
Jul 20, 2009 at 4:04 PM

Hi.

SmtpClient class has SendMail method.This method has some overload version.You may use this one.

SendMail(String inFrom, String inTo, String inCc, String inBcc, String inText)

inText parameter is the entire mail text data(with header and body consist of RFC822 and other RFC2045-2049).

And you could get entire text data of receive mail with GetMessageText method which Pop3Message class has.

You could create new Pop3Message object with this text data like below and could send SmtpMessage.

--------------------------------------------------------------

Pop3Client cl = new Pop3Client(...);

Int32 mailIndex = 1;

String mailText = cl.GetMessageText(mailIndex);

Pop3Message mg = new Pop3Message(mailText, mailIndex);

///and send SmtpMessage

SmtpClient scl = new SmtpClient(...);

scl.SendMail("FROMmailaddress", "TOmailaddress", "CCmailaddress", "BCCmailaddress", mailText);

---------------------------------------------------------------------------------------------------------

 

This code can perfectly forward mail without loosing any type of data.

regard.
 

May 13, 2010 at 10:05 PM

Well, this is definitely not working for me. For once, in the mailtext there is "+OK message follows" at the beginning which kinda messes things up.

Even if I remove this, I get an email which has for its text content the email I want to redirect - ie, the headers are seen as text. 

I also tried by doing pm.CreateSmtpMessage but that messes up all the content  encodings of the email so it's also not working well. 

:(