convert Rebex.Mail.MailMessage To System.Net.Mail.MailMessage

0 votes
asked Mar 15, 2012 by dikson8080 (120 points)
edited Mar 16, 2012

Could you please help me? What is the best way to convert Rebex.Mail.MailMessage To System.Net.Mail.MailMessage. I do not whant to save file.

Applies to: Rebex Secure Mail
commented Mar 15, 2012 by Tomas Knopp (58,890 points)
edited Mar 15, 2012

What do you need to acomplish with the System.Net.Mail.MailMessage? Do you want to send it via System.Net.Mail.SmtpClient or for something else? The best solution depends on the purpose.

commented Mar 15, 2012 by dikson8080 (120 points)
edited Mar 15, 2012

I would like to save it in my DB. The other application has to use it later.

commented Mar 15, 2012 by Lukas Pokorny (100,710 points)
edited Mar 15, 2012

How do you save an instance of System.Net.Mail.MailMessage into a database? As far as I know, it can either be sent through an SMTP server or saved into a spool directory. Is there anything I missed?

I'm asking because even though Rebex.Mail.MailMessage can't be easily converted into System.Net.Mail.MailMessage (the System MailMessage doesn't have Load method), it might be possible to save it into a DB the same way.

By the way, you can convert Rebex.Mail.MailMessage into a byte array using its ToByteArray method and save that into a database. Later, pass the byte array to Load method.

commented Mar 15, 2012 by dikson8080 (120 points)
edited Mar 15, 2012

To convert email in byte array or to serialize it. It's not a big deal. This mean that it's not a problem to save it in DB. The problem maybe later when third party program would like to use this object. I have Robex dll (and in general I like to use it) but they do not have it. This mean that I have to use one of the standard object. If you have any ideas, please let me know. Thank you for your time.

commented Mar 16, 2012 by Lukas Pokorny (100,710 points)
edited Mar 16, 2012

Actually, the result of both Rebex MailMessage.Save and .ToByteArray is a representation of the message in MIME format, which is well-defined and widely supported. Almost any email client can read it (Outlook 2010, Outlook Express, Windows Mail, Mozilla Thunderbird, etc.) and third-party mail components can read it (use .eml extension).

The only problem is with System MailMessage, which doesn't have Load or Save methods (actually, Save can be simulated by 'sending' it to a specified pickup folder, but you can't load the result back into System MailMessage), so its usefulness is very limited.

1 Answer

0 votes
answered Mar 16, 2012 by Lukas Pokorny (100,710 points)

Rebex.Mail.MailMessage can't be easily converted into System.Net.Mail.MailMessage because System MailMessage doesn't have Load method. See the comments above for suggested solutions.

...