This article is mainly for everyone to introduce in detail the C # Implementation of the method of sending mail, with a certain reference value, interested in small partners can refer to
The example of this article for you to share the Android nine Gongge picture display of the specific code for your reference, the specific content is as follows
#region Send mail section private static String Frommail = "1111@126.com"; Mailbox name private static String mailpwd = "111111"; Password private static string tomail = "2222@163.com"; Mailbox server private static string filestr;//current picture path, when adding attachments with///<summary>/////</summary>/ <param name= "FILEURL" > Accessory address to ~ </param>//<param name= "screen" > whether to send screenshots </param>//<re turns></returns> public static string SendMail (string fileUrl, String screens) {MailAddress from = new MailAddress (frommail); MailAddress to = new MailAddress (tomail); MailMessage message = new MailMessage (from, to); Message. Subject = "M mail" +11111;//subject message. subjectencoding = System.Text.Encoding.UTF8; Attachment attachfile = new Attachment (FILESTR); if (screen = = "True") message. Attachments.Add (Attachfile); string[] files = fileurl.split (' ~ '); for (int i = 0; i < files. Length; i++) { if (file.exists (files[i))) {Attachment attachFile1 = new Attachment (FILEURL); Message. Attachments.Add (ATTACHFILE1); }} try {SmtpClient client = new SmtpClient ("SMTP." + from. Host); SendMail (client, from, Mailpwd, to, message); Return "Send mail success! Includes attachment: "+ FileUrl +" included? "+ screen +" "+ DateTime.Now.ToString (); } catch (Smtpexception ex) {//If the error is not found for the server, try not to add SMTP. prefix server if (ex. StatusCode = = smtpstatuscode.generalfailure) {try {//some mail servers do not add SMTP. prefix Smt Pclient client = new SmtpClient (from. Host); SendMail (client, from, Mailpwd, to, message); Return "Send mail success! Includes attachment: "+ FileUrl +" included? "+ screen +" "+ DateTime.Now.ToString (); ' Catch (smtpexception err) {return ' failed to send mail! "+ Err. Message + "" + DateTime.Now.ToString (); }} else {return ' failed to send mail! "+ Ex. Message + "" + DateTime.Now.ToString (); }}}//Send mail according to specified parameters private static void SendMail (SmtpClient client, mailaddress from, string password, MailAddress to, MailMessage message) {//Do not use default credentials, note that this sentence must be placed in the client. Credentials the upper client. useDefaultCredentials = false; Specify the user name, password client. Credentials = new NetworkCredential (from. Address, password); Messages are sent over the network to the server client. Deliverymethod = Smtpdeliverymethod.network; try {client. Send (message); } catch {throw; finally {//releases the consumed resource message in a timely manner. Dispose (); }} #endregion