- Regular expressions for validating e-mail messages
- String emailstr = @ "^ ([\w-\.] +) @ ((\[[0-9]{1,3}\. [0-9] {1,3}\. [0-9] {1,3}\.) | ([\w-]+\.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (\]?) $";
- <summary>
- Send e-mail asynchronously
- </summary>
- <param name= "Fromemail" > Sender email </param>
- <param name= "Frompwd" > Sender email password </param>
- <param name= "Toemail" > Receiver email </param>
- <param name= "Subject" > Mail title </param>
- <param name= "Body" > E-mail inside empty </param>
- <param name= "Emailtype" > Mail type </param> smtp.163.com.cn; smtp.qq.com.cn; smtp.126.com.cn; smtp.sina.com.cn
- private void Sendemailasync (String fromemail, String frompwd, String toemail, string subject, String body, String Emailtyp E
- {
- MailAddress addrfrom = new MailAddress (Fromemail, Fromemail);
- MailAddress Addrto = new MailAddress (Toemail, Toemail);
- MailMessage mm = new MailMessage (Addrfrom, Addrto);
- Mm. bodyencoding = Encoding.UTF8;
- Mm. Isbodyhtml = true;
- Mm. Subject = Subject;
- Mm. BODY = body;
- if (!string. IsNullOrEmpty (Attfile))
- {
- Attachment att = new Attachment (Attfile, MediaTypeNames.Application.Octet);
- Contentdisposition cd = Att. Contentdisposition;
- Cd. CreationDate = File.getcreationtime (attfile);
- Cd. Modificationdate = File.getlastwritetime (attfile);
- Cd. Readdate = File.getlastaccesstime (attfile);
- Mm. Attachments.Add (ATT);//Add Attachments
- }
- NetworkCredential NC = new NetworkCredential (Fromemail, frompwd);
- SmtpClient smtp = new SmtpClient (emailtype);
- Smtp. useDefaultCredentials = false;
- Smtp. Credentials = NC;
- Smtp. Enablessl = false;
- Smtp. Deliverymethod = Smtpdeliverymethod.network;
- Smtp. Sendcompleted+=new Sendcompletedeventhandler (smtp_sendcompleted);
- Smtp. SendAsync (mm, "OK");
- }
- void Smtp_sendcompleted (object sender, AsyncCompletedEventArgs e)
- {
- if (e.userstate.tostring () = = "OK")
- MessageBox.Show ("Send successfully!", "hint", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
C # Send e-mail (async) Z