In the previous mailmessage saved as an EML file (C # + smtpclient), we used the Reflection Method to call system. net. mailwriter, the internal object of mail, implements saving mailmessage content as an EML file.
Through the previous implementation, I learned how to use reflection and played a role in attracting others.
Today, I occasionally saw the last code and found anotherNew WorldTo save the EML file, it becomes very simple. First, go back to the last resolved location:
In the last time, we overemphasized mailwriter here for the above image and ignored other parts. Below I will reproduce the above image:
Last time, I focused on the place where the above blue horizontal line was drawn. This time, we focused on the red line andDecimal numberAs you can seeSwitchThe process isSmtpclient. deliverymethodIs not related to mailmessage.
The above two places marked with red circles1In both cases2And3Location, while 2 and 3 are indeed the same, they all enterLabel_025dHere, the content of label_025d is as follows:
The core content above is the sentence that draws the red line, and the sentence actually returnsMailmessage. Send
The red lines above indicate that only writer performs some write operations without any network interaction, and writer is the stream that generates the EML file we mentioned last time.
Here, the problem is fixed. the. NET smtpclient for deliverymethod isSpecifiedpickupdirectoryAndPickupdirectoryfromiisOnlyGenerate an EML file under a specific directory..
ForPickupdirectoryfromiisIn this case, we need IIS support, not what we need. What we need isSpecifiedpickupdirectoryThis. The instance code is as follows:
Smtpclient SMTP = new smtpclient (); SMTP. enablessl = false; // It Must Be falsesmtp. deliverymethod = smtpdeliverymethod. specifiedpickupdirectory; SMTP. pickupdirectorylocation = @ "D: \ mail \"; // custom directory mailmessage MSG = new mailmessage (); MSG. subject = "Hello, I am deltacat"; MSG. from = new mailaddress ("deltacat@microsoft.com"); MSG. to. add ("zu14.cn@live.cn"); MSG. body = "Welcome to www.zu14.cn"; SMTP. send (MSG );
In the above method, you do not need to configure the SMTP server, and so on. The disadvantage is that the generated EML file name is a guid and cannot be controlled by yourself.
Okay, let's write this. I hope it will help you.