using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Mail;
/// <summary>
///mailhelper 的摘要说明
/// </summary>
public
class
mailhelper
{
public
mailhelper()
{
}
/// <summary>
/// 邮件发送操作
/// </summary>
/// <param name="Addressee">收件人地址</param>
/// <param name="From">发件人地址</param>
/// <param name="sendpassword">发件人密码</param>
/// <param name="Copy">抄送人地址</param>
/// <param name="secret">密送人地址</param>
/// <param name="Subject">发送主题</param>
/// <param name="Attachment">附件信息</param>
/// <param name="Body">邮件内容</param>
public
string
SendeEmal(
string
Addressee,
string
From,
string
sendpassword,
string
Copy,
string
secret,
string
Subject,
string
Attachment,
string
Body)
{
MailMessage objMailMessage;
MailAttachment objMailAttachment;
objMailMessage =
new
MailMessage();
objMailMessage.From = From;
objMailMessage.To = Addressee;
objMailMessage.Cc = Copy;
objMailMessage.Bcc = secret;
objMailMessage.Subject = Subject;
objMailMessage.Body = Body;
if
(Attachment !=
""
)
{
objMailAttachment =
new
MailAttachment(Attachment);
objMailMessage.Attachments.Add(objMailAttachment);
}
objMailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
,
"1"
);
string
name = From.Substring(0, From.IndexOf(
'@'
));
objMailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendusername"
, name);
objMailMessage.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendpassword"
, sendpassword);
string
smtp =
"smtp."
+ From.Substring(From.IndexOf(
'@'
) + 1);
SmtpMail.SmtpServer =
"smtp."
+ From.Substring(From.IndexOf(
'@'
) + 1);
try
{
SmtpMail.Send(objMailMessage);
return
"邮件发送成功!"
;
}
catch
(System.Net.Mail.SmtpException ex)
{
return
ex.Message;
}
}
}