asp.net 2.0 如何发送邮件

原创 2007年09月26日 17:52:00

asp.net2.0发送邮件

public static string SendMail(string smtp, string userName, string password, string title, string content, string send, string accept)
        {
            string result = string.Empty;
            SmtpClient client = new SmtpClient(smtp);
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential(userName, password);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            MailMessage message = new MailMessage();
            message.SubjectEncoding = Encoding.UTF8;
            message.BodyEncoding = Encoding.UTF8;
            message.From = new MailAddress(send, "loveayu", Encoding.UTF8);
            message.To.Add(new MailAddress(accept, "xiaOhui", Encoding.UTF8));
            message.IsBodyHtml = false;
            message.Subject = title;
            message.Body = content;
            try
            {
                client.Send(message);
                result = "操作成功";
            }
            catch (Exception sendE)
            {
                result = sendE.Message;
            }
            return result;
        } 

 

需要引进的命名空间是

using System.Net;
using System.Net.Mail;

内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:asp.net 2.0 如何发送邮件
举报原因:
原因补充:

(最多只允许输入30个字)