C # implements a simple smtpclient send message
Analysis
What you need
Send mail--Send content--Receive mail
Process (each function is applicable)
creating objects-assigning values to object properties-calling methods
Send e-mail
Create a Mailbox server object
Sender
Recipient
Create a Mail object
Message subject
Message content
Set up validation scenarios
Set up a qualification certificate
Send
Using System.Net; --Internet naming space
Using System.Net.Mail; --e-mail namespace under the Internet
Create a Sina Mailbox server object
smtpclient smtp = new smtpclient("host name or IP address of the SMTP transaction ");
SMTP. Enablessl = true;
SMTP. useDefaultCredentials = false;
mailaddress fr = new mailaddress(" Sender's email address "); -Who is the sender
mailaddress t = new mailaddress(" recipient's email address "); -Who is the recipient
Create a Mail object
mailmessage mail = new mailmessage( fr, t );
Mail. Subject = " mail subject "; --Assigning a value to the Message Object Title property
Mail. Body = " mail content "; --Assigning values to message object content properties
Create a validation scenario
networkcredential cred = new networkcredential(" Sender's email address ", " email password ");
Set up a qualification certificate
SMTP. Credentials = cred;
Send
SMTP. Send (mail);
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Net;//Internet NamespacesusingSystem.Net.Mail;//e-mail namespace under the Internet Public Partial class_default:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) {Button1.Click+=button1_click; } voidButton1_Click (Objectsender, EventArgs e) { stringto = TextBox1.Text;//Recipient Email Address stringtitle = TextBox2.Text;//message Header stringContent = TextBox3.Text;//Message Content//Create a Sina Mailbox server objectSmtpClient SMTP =NewSmtpClient ("smtp.sina.cn"); Smtp. Enablessl=true; Smtp. useDefaultCredentials=false; //who is the sender ?MailAddress FR =NewMailAddress ("1856***** @sina. CN"); //who's the recipient?MailAddress T =Newmailaddress (to); //sent Message objectMailMessage mail =NewMailMessage (FR, t); //Assigning a value to a Message Object title propertyMail. Subject =title; //Mail. Subject = "[Singularity Network] mailbox Verification mail"; //assigning values to Message object content propertiesMail. Body=content; //Mail. Body = "Welcome to register the Singularity network platform, your email verification code is [DRTR], please fill in 20 minutes, system mail do not reply!" "; //Mail. Body = "Yanzheng.qidian.com?i=kjwehrlkydafghdjfghwerkwehr"; //Create a Certificate objectNetworkCredential cred =NewNetworkCredential ("185******** @sina. CN","hq1234561"); //set up a qualification certificateSmtp. Credentials =cred; //SendSMTP. Send (mail); }}
View Code
WebForm "Send Mail"