Project requirements: Send emails at regular intervals and learn how to send emails
Here's a simple example. The ability to implement a simple send message, plus an attachment can add a property "Attachment", and then configure the path to the attachment
Demo download
The code has only a few of these, so you can send mail.
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Net.Mail;namespacesendmail{ Public classEmailhelper {/// <summary> ///Send mail/// </summary> /// <param name= "from" > Sender </param> /// <param name= "to" > Recipients </param> /// <param name= "title" > title </param> /// <param name= "Body" > Email content </param> /// <returns></returns> Public Static BOOLSend (mailaddress from,stringTo,stringSubjectstringbody) {MailMessage MailMessage=NewMailMessage (); Mailmessage.from= from; MAILMESSAGE.TO.ADD (to); MAILMESSAGE.TO.ADD ("[email protected]"); MAILMESSAGE.TO.ADD ("[email protected]"); Mailmessage.subject=subject; Mailmessage.body=body; Mailmessage.isbodyhtml=false; Mailmessage.priority=Mailpriority.high; SmtpClient SC=NewSmtpClient (); Sc. Host="smtp.qq.com";//If you use a non-QQ mailbox, you need to replaceSc. Port = -; Sc. useDefaultCredentials=true; Sc. Enablessl=false; Sc. Credentials=NewSystem.Net.NetworkCredential ("Account Number","Password"); Try{SC. Send (MailMessage); } Catch(Exception E1) {//throws an exception, does not process, lets the caller handle ThrowE1; } return true; } }}
"C #" #102 sending mail