Based on these properties and methods, you will certainly be able to understand how SmtpClient in the code sends emails out, with a few caveats noted here.
SmtpClient's Host property, the servers used to send different types of emails are different, so the Host property is also different, if you have more than one kind of mailbox, then you can see if the address of the outgoing server is different for each of your mailboxes, for example.
The outgoing mail server address of 163 mailbox is: smtp.163.com
The outgoing mail server address for Google Mail is: smtp.gmail.com
The outgoing mail server address for Hotmail mailbox is: smtp-mail.outlook.com
Foxmail harmonyQQ Mailbox sending item The server address is：smtp.qq.com
So in the code, a Switch is added to set the outgoing server address based on the sender email type ~∪~
Finally, when the email is sent successfully or fails, you need to call the DeleteFiles() function to delete the temporary files (attachments) just uploaded to the server, to say a few words about why to add this files folder, because this example on a computer to do tests do not need to add this folder at all, directly add the local files as attachments to the MailMessage instance on the line, but because the code for MailMessage to add attachments myEmail.Attachments.Add(new Attachment(ServerFileName)); It is running on the server side, so if the program is published, it is not feasible to perform the operation offsite, so you need to upload the attachment to the server side first (here just add the files folder to the server side to store temporary files), then add that attachment for MailMessage, and finally clean up the attachment uploaded to the client.
Make it like this for now, and optimize it later when there is a need for it.
The original is not easy to create and ends with a reference to the article.
This example is a modification of this article
>>1、Artificial intelligence can now model in 3D 3D printing future without having to model it yourself2、Appendicitis Facebooks recent tweaks remind me of Racer3、Countries could be caught off guard if satellites experience cyber attacks4、Wang Pengjie chairman of the Henan Provincial Committee of the Communist Party of China investigated a number of big data enterprises on Wisdom Island and made three recommendations5、Domain wall detection queries and solutions