62,039
社区成员
发帖
与我相关
我的任务
分享
private void SendMyMail()
{
string strHost = string.Empty;
string strAccount = string.Empty;
string strPwd = string.Empty;
string strFrom = string.Empty;
strHost = "smtp.sina.com.cn"; //STMP服务器地址
strAccount = "ceshi1852123"; //SMTP服务帐号(我在新浪上注册的免费邮箱帐号)
strPwd = "951230"; //SMTP服务密码
strFrom = "ceshi1852123@sina.com"; //发送方邮件地址
string to = "vipgan@yahoo.com.cn";
string title = "这是一个测试邮件";
string content = "测试邮件的正文";
SmtpClient _smtpClient = new SmtpClient();
_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式
_smtpClient.Host = strHost; ;//指定SMTP服务器
_smtpClient.Credentials = new System.Net.NetworkCredential(strAccount, strPwd);//用户名和密码
MailMessage _mailMessage = new MailMessage(strFrom, to);
_mailMessage.Subject = title;//主题
_mailMessage.Body = content;//内容
_mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码
_mailMessage.IsBodyHtml = true;//设置为HTML格式
_mailMessage.Priority = MailPriority.High;//优先级
try
{
_smtpClient.Send(_mailMessage);
// return true;
}
catch(Exception ex)
{
Response.Write(ex.Message);
// return false;
}
}