using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
/// <summary>
/// Summary description for SendEmail
/// </summary>
public class SendEmail
{
public SendEmail()
{
//
// TODO: Add constructor logic here
//
}
public static string sendEmail(string ToWhom, string FromWho, string Topic, string Body, string sAttach)
{
string strMessage = "";
MailMessage MyEmailMessage = new MailMessage();
MyEmailMessage.From = FromWho.Trim();
MyEmailMessage.To = ToWhom.Trim();
MyEmailMessage.Subject = Topic.Trim();
MyEmailMessage.Body = Body.Trim();
MyEmailMessage.BodyFormat = MailFormat.Text;
MyEmailMessage.Priority = MailPriority.High;
//SmtpMail.SmtpServer = "192.168.0.17";
if (!sAttach.Equals(""))
{
char[] delim = new char[] { ',' };
foreach (string sSubstr in sAttach.Split(delim))
{
MailAttachment myAttachment = new MailAttachment(sSubstr);
MyEmailMessage.Attachments.Add(myAttachment);
}
}
//以下内容是为服务器认证语句
MyEmailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
MyEmailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "name");//用户名
MyEmailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "pwd");//邮箱密码
SmtpMail.SmtpServer = "mail.eguo.com";
try
{
SmtpMail.Send(MyEmailMessage);
strMessage = "向" + MyEmailMessage.To + "发送的邮件已经成功发送";
}
catch (Exception ee)
{
//strMessage = "邮件发送失败!无法连接服务器." + ee.Message;
strMessage = "邮件发送失败!无法连接服务器.请您稍后在试";
}
return strMessage;
}
}