C # Save mailmessage as a local EML file (. NET + smtpclient)

Source: Internet
Author: User
Tags mailmessage smtpclient

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.