vs2005发送邮件

http://www.sina.com.cn 2008年06月20日 10:27  IT168.com

【IT168技术文档】

    void send()
{
MailMessage message = new MailMessage();
message.From = new MailAddress("sgyljzf@gmail.com","hoho~~邮件发送成功!");
message.To.Add(new MailAddress("sguoy_2007@163.com")); // the email you want to send email to
            message.Subject = "A test email";
message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Body = "资料已经成功提交!";
message.Priority = MailPriority.High;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587); // 587;//Gmail使用的端口
            client.Credentials = new System.Net.NetworkCredential("sgyljzf@gmail.com", "password"); // Your user name & password
            client.EnableSsl = true; //经过ssl加密 
            object userState = message;
try
{
client.Send(message);
Response.Write("邮件发送到" + message.To.ToString() + "<br>");
}
catch (Exception ee)
{
Response.Write(ee.Message + "<br>" + ee.InnerException.Message);
}
}

Powered By Google
不支持Flash
·城市对话改革30年 ·新浪城市同心联动 ·诚招合作伙伴 ·企业邮箱畅通无阻
不支持Flash