请问怎么在网页中实现根据条件自动发送指定内容到指定的邮箱
请各位好心人帮帮忙,很着急,谢谢

解决方案 »

  1.   

    写个发邮件的类 就ok了,
    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;
    }


    }
      

  2.   

    public static void SendEmail(string _to,string _cc,string _subject,string _content)
    {
    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;
    }
      

  3.   

    上面是我开始的一段实际代码!只是为了安全,隐掉了一些敏感信息;
    需要提示的是:
    1、smtp的地址必须是真实的IP,否则第三方邮件网关会拒收;
    2、注意防火墙的问题。