Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;
Using System.Net.Mail;
Namespace WindowsFormsApplication1
{
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
Sendsmforgmail ("ouyjpem@gmail.com", "Akdkdls", "Li Ming", "Test", "good recently." "," 13577221209@139.com ");
}
private string Sendsmforgmail (string sender, String pwd, string name, String smtitle, String smcontent, string receiver)
{
Example Sendsmforgmail ("Liming@gmail.con", "Li Ming", "Test", "recent good.") "," limei@163.com ")
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage ();
Msg. To.add (PhoneNumber + "@139.com");
Msg. To.add (receiver);
Msg. To.add ("");
Msg. To.add ("b@b.com");
/*
* Msg. To.add ("b@b.com");
* Msg. To.add ("b@b.com");
* Msg. To.add ("b@b.com"); can be sent to many people
*/
Msg. Cc. Add ("CC address");
/*
* Msg. Cc. ADD ("c@c.com");
* Msg. Cc. ADD ("c@c.com"); can be copied to many people
*/
Msg. from = new MailAddress (sender, Name, System.Text.Encoding.UTF8);
* * Above 3 parameters are the sender's address (can be casually written), sender name, code * *
Msg. Subject = smtitle;//message Header
Msg. subjectencoding = system.text.encoding.utf8;//message header encoding
Msg. BODY = smcontent;//message Content
Msg. bodyencoding = system.text.encoding.utf8;//message content encoding
Msg. isbodyhtml = false;//is an HTML message
Msg. Priority = mailpriority.high;//Message priority
SmtpClient client = new SmtpClient ();
Client. Credentials = new System.Net.NetworkCredential (sender, PWD);
Write your email and password above
Client. Port = Ports Used by 587;//gmail
Client. Host = "smtp.gmail.com";
Client. Enablessl = true;//after SSL encryption
Object userState = msg;
Try
{
Client. SendAsync (msg, userState);
Client. Send (msg);
Just a little bit easier to be a client. Send (msg);
MessageBox.Show ("Send Success");
TextBox2.Text = TextBox2.Text + DateTime.Now.ToString () + "Have sent a message!" + "/r/n";
return "1";
}
catch (System.Net.Mail.SmtpException ex)
{
MessageBox.Show (ex. Message, "Send mail Error");
TextBox2.Text = TextBox2.Text + DateTime.Now.ToString () + "" + Ex. Message + "/r/n";
return "0";
}
}
}
}