ASP. NET send mail

Source: Internet
Author: User
Tags mailmessage net send smtpclient

Common method

 

/// <Summary>
/// Send an activation code email
/// </Summary>
/// <Param name = "emailinfo"> email </param>
Public void sendemail (filmsys. model. emailinfo)
{
Try
{
// The code must be gb2312.
Encoding encoding = encoding. getencoding (936 );
Mailmessage message = new mailmessage (
New mailaddress (emailinfo. sendemailaddress, emailinfo. sendemailname, encoding), // The first is the sender's address, and the second parameter is the display sender new mailaddress ("hfxliyunfang@163.com", "Xi'an day Electronic Technology Service Company", encoding)
New mailaddress (emailinfo. receiveemailaddress); // recipient's email address
Message. subjectencoding = encoding;
Message. Subject = emailinfo. Subject; // "Welcome to join Xi'an jitian Electronic Technology Service Company"; // Title
Message. bodyencoding = encoding;
Message. isbodyhtml = true; // specifies the HTML language for Email Subject recognition.
Message. body = emailinfo. content; // "please perform email verification to complete the last step of your registration. Click the link below to activate your account: <br> <a target = '_ blank' rel = 'nofollow' style = 'color: #0041d3; text-Decoration: underline' href = 'HTTP: // www.xxx.com/regedit/regeditok.aspx? Code = "+ numcode +" & uid = "+ cu_name +" "'> http://www.XXX.com.cn/regedit/regeditOK.aspx? Code = "+ numcode +" & uid = "+ cu_name +" </a> "; // subject
Smtpclient = new smtpclient (emailinfo. smtpclient); // Mail Server "smtp.163.com"
Smtpclient. Credentials = new networkcredential (emailinfo. sendemailaddress, emailinfo. sendemailpwd); // username and password of the mailbox
Smtpclient. Timeout = 999999;
Smtpclient. Send (Message );
}
Catch (exception)
{
// Throw new exception (ex. Message );
}
}

 

 

Entity class

Public class emailinfo
{
Private string sendemailaddress;

Public String sendemailaddress
{
Get {return sendemailaddress ;}
Set {sendemailaddress = value ;}
}

Private string sendemailname;

Public String sendemailname
{
Get {return sendemailname ;}
Set {sendemailname = value ;}
}

Private string sendemailpwd;

Public String sendemailpwd
{
Get {return sendemailpwd ;}
Set {sendemailpwd = value ;}
}

Private string receiveemailaddress;

Public String receiveemailaddress
{
Get {return receiveemailaddress ;}
Set {receiveemailaddress = value ;}
}

Private string subject;

Public String subject
{
Get {return subject ;}
Set {subject = value ;}
}

Private string content;

Public String content
{
Get {return content ;}
Set {content = value ;}
}

Private string smtpclient;

Public String smtpclient
{
Get {return smtpclient ;}
Set {smtpclient = value ;}
}

Private string numcode;

Public String numcode
{
Get {return numcode ;}
Set {numcode = value ;}
}

Private string userid;

Public String userid
{
Get {return userid ;}
Set {userid = value ;}
}

}

 

 

Add try catch () to the call Method ()

String useremail = DT. Rows [I] ["useremail"]. tostring ();
// Send an email
Filmsys. model. emailinfo = new filmsys. model. emailinfo ();
Emailinfo. sendemailaddress = "newmoviess@163.com"; // sender address
Emailinfo. sendemailname = "Yun xuange film Network"; // sender name
Emailinfo. sendemailpwd = "mv123456"; // sender Password
Emailinfo. receiveemailaddress = useremail; // recipient address
Emailinfo. smtpclient = "smtp.163.com"; // The email server smtp.163.com smtp.qq.com
Emailinfo. Subject = This. emailtitle. Text; // mail title
Emailinfo. numcode = ""; // automatically generated verification number
Emailinfo. userid = ""; // user ID
Emailinfo. content = This. ckfilmcontent. Text; // you can use HTML
Sendemail (emailinfo );

Related Article

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.