程序如下: protected void Page_Load(object sender, EventArgs e)
    {
        if(Bind())
        {
            lblMailStatus.Text = "Mail successfully sent."; 
        }
      
        //UPDATE STATUS 
           }
    private bool Bind()
    {
        // CREATE A MAIL MESSAGE 
        System.Web.Mail.MailMessage myEmail = new System.Web.Mail.MailMessage();
        // SET MESSAGE PARAMETERS 
        myEmail.From = "[email protected]";
        myEmail.To = "[email protected]";
        myEmail.Subject = "ceshiyoujian";
        //myEmail.BodyFormat = System.Web.Mail.MailFormat.Html;
        myEmail.Body = "The sunglasses you expressed interest in are now in stock.";
        //SEND THE MESSAGE 
        System.Web.Mail.SmtpMail.SmtpServer = "smtp.gmail.com";
        System.Web.Mail.SmtpMail.Send(myEmail);        return true;
 
    }错误:服务器拒绝发件人发送注:SmtpServer = "smtp.gmail.com"; outlook express 我已经设置好了,能接收到gmail的邮件,但是不知道放在程序里发邮件发不出去。 请大侠们指教,多谢!

解决方案 »

  1.   

    原因能是: 
    1 你的邮箱帐号不是VIP的 
    2 各家邮件服务器提供商对免费邮箱的SMTP处理机制不一样,基本上都有所限制,除了VIP 
    3 如果有时可以发有时不可以发,那是因为邮件服务器每次都判断发出邮件的地址频率很高或 
      是tom.com|sohu.com|163.com...其他邮件服务商的。如果是这样把该邮件判断成垃圾邮件或不受理的邮件 解决办法: 
      1 申请VIP邮箱,会开通通畅的SMPT,那就可以合法使用了 
      2 发邮件时,发出人邮箱地址的@后缀用随机算法(比如 是 [email protected]\[email protected]...)构造后再发出, 
        就可以解决问题。当然,这样做的毙命是收件人收到邮件后看到的发件人邮箱地址的@???就不是真实的,就说他无法 
        直接用该地址给回复邮件! 不知道我表达的是否清楚? 那还有其他方法: 
    1 自己去了解底层的邮件协议,像FOXMAIL那样做,内置邮件服务系统 
    2 自己构建邮件系统,第3方的 
    3 就是上面说的:@地址混淆法 
      适用于网站,因为收件人一般不会给网站回邮件,如果你要做FOXMAIL,那就要用1,2方法了!
      

  2.   

    //发邮件
    //confusionFromMail:是否产生迷惑邮件服务器的邮件地址
    //EncryptOption:是否加密邮件
    //mailDESKey:加密邮件时的DES KEY
    public static void SendMail(
                string smtpHost, int smtpPort, 
                string smtpUser, string smtpPassword,
                string fromMail, string sender, 
                string toMail, string receiver,
                string subject, string body,
                string attachment, string attachName,
                bool smtpByIIS, bool smtpEnableSSL, 
                bool smtpEnableAuth, bool confusionFromMail, EncryptOption mailEncrypt, string mailDESKey
                )
            {
                //Smtp Server
                SmtpClient smtpServer = new SmtpClient(smtpHost, smtpPort);
                smtpServer.UseDefaultCredentials = true;
                if (smtpEnableAuth)
                {
                    smtpServer.UseDefaultCredentials = false;
                    smtpServer.Credentials = new System.Net.NetworkCredential(smtpUser, smtpPassword);
                }
                smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpServer.EnableSsl = smtpEnableSSL;            //Confusion Mail 产生迷惑邮件服务器的邮件地址
                string frMail = fromMail;
                if (confusionFromMail) frMail = BMailHelper.MakeConfusionMail(fromMail);            //Mail Message
                Encoding encoding = Encoding.GetEncoding("GB2312");
                MailAddress fromMailAddress = new MailAddress(frMail, sender, encoding);
                MailAddress toMailAddress = new MailAddress(toMail, receiver, encoding);
                MailMessage mailMessage = new MailMessage(fromMailAddress, toMailAddress);
                mailMessage.Priority = MailPriority.High;            //Attachment
                string encryptAttachment = EncryptHelper.SignatureAndEncrypt(attachment, mailDESKey, mailEncrypt);
                System.Net.Mail.Attachment att = System.Net.Mail.Attachment.CreateAttachmentFromString(encryptAttachment, BFormatingMail.AttachName);
                att.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
                att.NameEncoding = encoding;
                att.Name = attachName;
                mailMessage.Attachments.Add(att);            //Body
                mailMessage.SubjectEncoding = encoding;
                mailMessage.Subject = subject;
                mailMessage.BodyEncoding = encoding;
                mailMessage.Body = EncryptHelper.SignatureAndEncrypt(body, mailDESKey, mailEncrypt);            //Sending
                smtpServer.Send(mailMessage);
                smtpServer.ServicePoint.CloseConnectionGroup(smtpServer.ServicePoint.ConnectionName);
            }        /// 产生迷惑邮件服务器的邮件地址
            /// <param name="targetMail">发件地址.</param>
            public static string MakeConfusionMail(string targetMail)
            {
                string s1 = BFormatingMail.GetEmailPart(targetMail, 1) ?? string.Empty;            string[] domains = new string[] {
                    "asys.com", "aspt.com", "aast.com", "aaet.com",
                    "bsys.com", "bspt.com", "bast.com", "baet.com",
                    "csys.com", "cspt.com", "cast.com", "caet.com",
                    "dsys.com", "dspt.com", "dast.com", "daet.com",
                    "esys.com", "espt.com", "east.com", "eaet.com",
                    "fsys.com", "fspt.com", "fast.com", "faet.com",
                    "gsys.com", "gspt.com", "gast.com", "gaet.com",
                    "amou.com", "acat.com", "apig.com", "acar.com",
                    "bmou.com", "bcat.com", "bpig.com", "bcar.com",
                    "cmou.com", "ccat.com", "cpig.com", "ccar.com",
                    "dmou.com", "dcat.com", "dpig.com", "dcar.com",
                    "emou.com", "ecat.com", "epig.com", "ecar.com",
                    "fmou.com", "fcat.com", "fpig.com", "fcar.com",
                    "hmou.com", "hcat.com", "hpig.com", "hcar.com",
                    "imou.com", "icat.com", "ipig.com", "icar.com",
                    "jmou.com", "jcat.com", "jpig.com", "jcar.com",
                    "kmou.com", "kcat.com", "kpig.com", "kcar.com",
                    "lmou.com", "lcat.com", "lpig.com", "lcar.com",
                    "mmou.com", "mcat.com", "mpig.com", "mcar.com",
                    "nmou.com", "ncat.com", "npig.com", "ncar.com",
                    "ayal.com", "ayat.com", "aybt.com", "ayag.com",
                    "byal.com", "byat.com", "bybt.com", "byag.com",
                    "cyal.com", "cyat.com", "cybt.com", "cyag.com",
                    "dyal.com", "dyat.com", "dybt.com", "dyag.com",
                    "eyal.com", "eyat.com", "eybt.com", "eyag.com",
                    "fyal.com", "fyat.com", "fybt.com", "fyag.com",
                    "gyal.com", "gyat.com", "gybt.com", "gyag.com",
                    "hyal.com", "hyat.com", "hybt.com", "hyag.com",
                    "iyal.com", "iyat.com", "iybt.com", "iyag.com",
                    "jyal.com", "jyat.com", "jybt.com", "jyag.com",
                    "kyal.com", "kyat.com", "kybt.com", "kyag.com"
                };
                int index = (new Random()).Next(1, domains.Length);
                if (index <= 0) index = 1;
                string s2 = domains[index - 1];
                return string.Format("{0}@{1}", s1, s2);
            }
      

  3.   

    gmail 若要使用 tcp 套接字发送, 需要使用 sslsmtp, pop3 都要走 ssl 通道.
      

  4.   

    换其他邮箱试试,可能不支持SMTP。也可能邮箱禁止。
    用jmail试试
      

  5.   

    前几天刚好看了看 ssl 的, 走 ssl 通道其实也不麻烦, 看看码子      // 已经调用了 socket connect 到服务器
          _networkStream = new NetworkStream(_socket, true);
          // 如果是走 ssl 方式
          if (UseSsl)
          {
            // 
            SslStream sslStream = new SslStream(
                _networkStream,
                false,
                new RemoteCertificateValidationCallback(ValidateServerCertificate),// 
                null
                );
            try
            {
              sslStream.AuthenticateAsClient(_proxy.TargetHost);
            }
            catch (System.Security.Authentication.AuthenticationException e)
            {
              string _lastError = e.Message;
              if (e.InnerException != null)
              {
                _lastError += Environment.NewLine + e.InnerException.Message;
              }
              _networkStream.Close();
              throw new SmtpException("Cannot create SSL tunnel to smtp host(" + _proxy.TargetHost + ":" + _proxy.TargetPort + ").", e);
            }        _streamReader = new StreamReader(sslStream, System.Text.Encoding.ASCII);
            _streamWriter = new StreamWriter(sslStream, System.Text.Encoding.ASCII);
            _streamWriter.AutoFlush = true;
          }
          else// 非 ssl 方式
          {
            _streamReader = new StreamReader(_networkStream, System.Text.Encoding.ASCII);
            _streamWriter = new StreamWriter(_networkStream, System.Text.Encoding.ASCII);
            _streamWriter.AutoFlush = true;
          }
          // 下面跟服务器的交互使用 streamReader streamWriter 
          // 好在 .net 封装 ssl stream    static bool ValidateServerCertificate(
              object sender,
              System.Security.Cryptography.X509Certificates.X509Certificate certificate,
              System.Security.Cryptography.X509Certificates.X509Chain chain,
              SslPolicyErrors sslPolicyErrors)
        {
          if (sslPolicyErrors == SslPolicyErrors.None)
            return true;      //Console.WriteLine("验证错误: {0}", sslPolicyErrors);      return false;
        }
      

  6.   


    对, gmail 需要到网页的界面中打开 pop 功能才行.前几天测试收发都可以的.
      

  7.   

    gmail是用了ssl
    端口号也不是默认的25,具体是什么忘了
      

  8.   


    pop3 是 995
    smtp 是 465gamil web mail 的配置里头有说明.
      

  9.   

    通道设置好了,在outlook express 里面可以发送邮件的,可是用.net自带的邮件系统发邮件却不行
      

  10.   

    你搜搜开源的代码, 有的支持 ssl, 如果找不到, 自己修改代码以支持 ssl 不难
    就是在连接建立后, 交互开始之前, 做一下 ssl 认证.