请问怎么在网页中实现根据条件自动发送指定内容到指定的邮箱
请各位好心人帮帮忙,很着急,谢谢
请各位好心人帮帮忙,很着急,谢谢
解决方案 »
- 高手请进 调用淘宝API添加一张图片!!!
- aspnet 请高手指教
- 修改csproj的编译脚本,是否可以实现VSS的签入和签出
- 大家在做项目的时候是新建“项目”还是新建“网站”?
- 关于TransactionScope和存储过程的问题
- 请问window2003的域认证怎样才能让匿名登录不弹出域认证登录框
- GridView的又一个问题?
- 如何在父窗体中改变Iframe
- 在页面的生存期内,自定义组合控件的CreateChildControls方法为何会被两次调入?
- gridview中RowCreated事件的问题 请大家进来讲解一下错误原因!
- 一个非常郁闷的问题:"输入字符串的格式不正确。" 急用
- 用VS.NET 2005的crystal report作deployment是否需要license?
public static bool SendMail(string toEmail,string subject,string body)
{
try
{
SmtpMail.SmtpServer = "发邮件的服务器如 mail.163.com";
MailMessage message = new MailMessage();
//定义SMTP邮件服务器需要身份认证
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");//是否验证身份
//认证的用户名
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "帐号");
//认证密码
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","密码");
message.Subject = subject; //标题
message.To = toEmail; //email地址
message.From = "。"; //发件人的名和email地址
message.BodyFormat = MailFormat.Html;
message.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
message.Body = body;
SmtpMail.Send(message);
return true;
}
catch
{
return false;
}
}
{
string to = _to;
string cc = _cc;
string subject = _subject;
string content = _content;
to = to.Replace(",",",").Trim(',').Trim();
cc = cc.Replace(",",",").Trim(',').Trim();
to = to.Replace(",,",",");
cc = cc.Replace(",,",",");
/*
string[] ccArray;
string[] toArray;
System.Text.RegularExpressions.Regex regex = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
ccArray = cc.Split(',');
toArray = to.Split(',');
cc = String.Empty;
to = String.Empty;
for(int i = 0;i < ccArray.Length;i++)
{
if(regex.IsMatch(ccArray[i],0))
{
cc += "," + ccArray[i];
}
}
for(int i = 0;i < toArray.Length;i++)
{
if(regex.IsMatch(toArray[i],0))
{
to += "," + toArray[i];
}
}
cc.Trim(',');
to.Trim(',');
*/
if(to.IndexOf('@') == -1 && cc.Trim().IndexOf('@') == -1)
{
return;
} System.Web.Mail.MailMessage mail = new MailMessage();
mail.From = "*@*";
mail.To = to;
mail.Cc = cc;
//mail.Attachments =
mail.Priority = MailPriority.High;
mail.Subject = " " + subject;
string body = "\r\r\n注意:该邮件由系统自动发送。\r"
mail.Body = content + body;
mail.BodyFormat = MailFormat.Text;
//mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 60);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "0"); //basic authentication
//mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "***@163.com"); //set your username here
//mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "***"); //set your password here
System.Web.Mail.SmtpMail.SmtpServer = "172.16.1.221";
try
{
SmtpMail.Send(mail);
}
catch(Exception exx)
{
throw exx;
}
需要提示的是:
1、smtp的地址必须是真实的IP,否则第三方邮件网关会拒收;
2、注意防火墙的问题。