WebForm "Send Mail"

Source: Internet
Author: User
Tags mailmessage smtpclient

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.