您的位置:首页 > 编程语言 > C#

C#发送邮件

2009-11-30 17:42 246 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

using VehicleManage.Model;
using VehicleManage.DAL;
namespace VehicleManage.BLL
{
public static class SendEmails
{
private static MileageService mService = new MileageService();
private static SuperspeedService sService = new SuperspeedService();
private static FireDownBodyService fdbService = new FireDownBodyService();

/// <summary>
/// 发送邮件
/// </summary>
/// <param name="toname">收件人名称</param>
/// <param name="toemail">收件人邮件地址</param>
/// <param name="smtpclient">伺服器</param>
/// <param name="fromname">发件人名称</param>
/// <param name="fromemail">发件人邮件地址</param>
/// <param name="password">发件人邮箱密码</param>
/// <param name="subject">邮件标题</param>
/// <param name="body">邮件主体</param>
/// <returns></returns>
public static bool SendEmailForGetpass(string toname, string toemail, string smtpclient, string fromname, string fromemail, string password, string subject, string body)
{
try
{
MailAddress from = new MailAddress(fromemail, fromname);//发件人
MailAddress to = new MailAddress(toemail, toname);//收件人
MailMessage message = new MailMessage(from, to);
message.Subject = subject;
message.Body = body;
message.Priority = MailPriority.High;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient(smtpclient);//伺服器,如"smtp.163.com"
client.Credentials = new System.Net.NetworkCredential(fromemail, password);
client.Send(message);

return true;
}
catch(Exception e)
{
return false;
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# string exception class