There are 2 ways to do this:
The first type:
usingSystem;usingSystem.Net.Mail;//at that time the test is QQ mailboxclasstestmail{Static voidMain (string[] args) { stringMailcontent ="Message Content"; MailMessage msg=NewSystem.Net.Mail.MailMessage (); Msg. To.add ("[email protected],[email protected]");//Recipient//Sender InformationMsg. from =NewMailAddress ("[email protected]","Sender's name", System.Text.Encoding.UTF8); Msg. Subject="This is a test message .";//message HeaderMsg. subjectencoding = System.Text.Encoding.UTF8;//Title EncodingMsg. Body = mailcontent;//message bodyMsg. Bodyencoding =System.Text.Encoding.UTF8; Msg. Isbodyhtml=true;//whether the HTMLMsg. priority = Mailpriority.high;//Priority LevelSmtpClient client =NewSmtpClient (); //Note: The following password is the authorization code, not your password to log in QQ, view method: QQ Mailbox---settings insideClient. Credentials =NewSystem.Net.NetworkCredential ("[email protected]","ASDFGHJKL"); Client. Enablessl=true; Client. Port=587;//443Client. Host ="smtp.qq.com";//mail.adient.com ObjectUserState =msg; Try{client. Send (msg); //MessageBox.Show ("sent successfully"); } Catch(Exception ex) {//MessageBox.Show (ex. Message, "Error sending message"); } }}
The second type:
//The mailbox of Outlook Yanfeng was tested at the timeusingSystem.Net.Mail;namespaceconsoleapplication11{classProgram {Static voidMain (string[] args) {MailMessage mail=NewMailMessage (); //set the title of a messageMail. Subject ="Test Message"; //set the sender of a message//Mail. from = new MailAddress ("[Email protected]", "xiao_1006"); //Sender's e-mail address, followed by parameter Zhang Meng: The recipient sees the name of the senderMail. from =NewMailAddress ("[email protected]","Zhang Meng"); //set the recipient of the message, Zmeng no useMail. To.add ("4[email protected],[email protected]"); //set up cc people for a message//Mail. Cc. ADD (New MailAddress ("[Email protected]", "Nick")); //set the contents of a messageMail. Body ="is the test with 111 ."; Mail. Bodyencoding=System.Text.Encoding.UTF8; Mail. Isbodyhtml=true; Mail. Priority=Mailpriority.normal; Mail. Deliverynotificationoptions=deliverynotificationoptions.onsuccess; SmtpClient Client=NewSmtpClient (); //the name of the mail server, to ask the other company only knowClient. Host ="smtp.ga.adient.com"; //E -Mail The port number, to ask the other company only knowClient. Port = -; Client. useDefaultCredentials=false; //client. Credentials = new System.Net.NetworkCredential ("[Email protected]", "xiao_1006"); //Sender's account number and passwordClient. Credentials =NewSystem.Net.NetworkCredential ("[email protected]","Yfas123"); Client. Deliverymethod=smtpdeliverymethod.network; Client. Send (mail); } }}
Send mail in C #