Recently do not know whether the IP of the server is 163 blocked, the site sent out the mail, so think of a way to save the message, and then download the reply, find a lot of methods are not good use, I tried some, according to the garden some code rewrite, measured available
Define the extension method first:
The framework version used for. NET 3.5
namespacesystem.net.mail{ Public Static classMailmessageextend {//1 Public Static byte[] ToArray ( Thismailmessage msg) { ConstBindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic |BindingFlags.FlattenHierarchy; using(varms =NewMemoryStream ()) { varAssembly =typeof(System.Net.Mail.SmtpClient). Assembly; varWritertype = assembly. GetType ("System.Net.Mail.MailWriter"); varwriter = Activator.CreateInstance (Writertype, Flags,NULL,New Object[] {ms}, CultureInfo.InvariantCulture); Msg. GetType (). GetMethod ("Send", flags). Invoke (MSG,New[] {writer,true }); returnMs. ToArray (); } } //2 Public Static voidToArray ( ThisMailMessage msg,stringPath) { ConstBindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic |BindingFlags.FlattenHierarchy; using(varms =NewMemoryStream ()) { varAssembly =typeof(System.Net.Mail.SmtpClient). Assembly; varWritertype = assembly. GetType ("System.Net.Mail.MailWriter"); varwriter = Activator.CreateInstance (Writertype, Flags,NULL,New Object[] {ms}, CultureInfo.InvariantCulture); Msg. GetType (). GetMethod ("Send", flags). Invoke (MSG,New[] {writer,true }); byte[] content =Ms. ToArray (); using(varFile =NewFileStream (Path, FileMode.Create)) {file. Write (Content,0, content. Length); } } } }}
I rookie, define the extension method, how to define, make a long time only understand, actually outside also to set a layer corresponding namespace
The use of the example is very simple, it is very convenient to change, Method 2 is my own convenience to use the extended
// Generate MailMessage " 127.0.0.1 " ); Project inside the method, return MailMessage
string string. Format ("/eml/{0}.eml"
// calling the method without the path parameter is called Method 1, and you need to receive the byte array yourself
Response.Redirect (path);
Reference address
Http://www.cnblogs.com/westsource/archive/2010/11/01/1865992.html
In this blog post
The next thing to do is to use the Mailwriter internal (internal) class, which is very simple, of course:
The following code in this sentence
It's written in this way,
Probably in Msg. GetType (). GetMethod (...) This place is always an error.
Also did not find out what is the reason, have to know in the following reply, I began to think is the framework version of the reason, several versions of the background have tried not
2015-07-30
Save MailMessage message information as a local EML file in. Net