在http://win.51aspx.com/CV/GroupSendMail/
下在了一个,运行收不到邮件
我自己参照csdn写了一个最简单的
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;namespace 发送邮件
{
    class Program
    {
        static void Main(string[] args)
        {
            string to = "[email protected]";
            string from = "[email protected]";
            //string to = "[email protected]";
            //string from = "[email protected]";
            string subject = "Using the new SMTP client.";
            string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
            MailMessage message = new MailMessage(from, to, subject, body);
            SmtpClient client = new SmtpClient("smtp.163.com");
            Console.WriteLine("Changing time out from {0} to 100.", client.Timeout);
            client.Timeout = 100;
            // Credentials are necessary if the server requires the client 
            // to authenticate before it will send e-mail on the client's behalf.
            //client.Credentials = CredentialCache.DefaultNetworkCredentials;
            try
            {
                client.Send(message);
            }
            catch (SmtpException se)
            {
                Console.WriteLine(se.Message);
            }
        }
    }
}
输出超时,应该怎么办?
大家有C#编写的邮件既可以发送也可以收到的程序共享一下 啊。

解决方案 »

  1.   


    public class MailHelper
        {
            /// <summary>
            /// 发邮件
            /// </summary>
            /// <param name="to">收件人(以分号分隔的电子邮件地址列表)</param>
            /// <param name="subject">主题</param>
            /// <param name="message">邮件体</param>
            /// <param name="ishtml">是否使用HTML发出</param>
            /// <example>SendMail("[email protected]", DateTime.Now.ToString(), DateTime.Now.ToString());</example>
            public static void SendMail(string to, string subject, string message, bool ishtml, Encoding encode)
            {
                if (ishtml == false)
                {
                    //message = CharHelper.Html2Text(message);
                }
                SmtpClient smtpClient = new SmtpClient();            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("/");            MailSettingsSectionGroup netSmtpMailSection = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");            using (MailMessage msg = new MailMessage(netSmtpMailSection.Smtp.From, to, subject, message))
                {
                    msg.BodyEncoding = encode;
                    msg.IsBodyHtml = ishtml;
                    smtpClient.Send(msg);
                }
            }
      

  2.   

    好像给qq邮箱发有特殊限制吧试试别的邮箱,应该就没问题的,只要smtp没写错
      

  3.   

    而且,你163的邮箱把smtp/pop3开启了么?好像新申请的邮箱都不给开了,老用户能开
      

  4.   


    Windows Email Client application using .NET (C#)
      

  5.   

    POP3 Email Client (.NET 2.0)
      

  6.   

    使用其他邮箱看看
    public void MailSend(string MailFrom,string MailTo,string MailPwd,string Mailtitle,string MailCon)  
      {  
      MailMessage MyMail = new MailMessage();  
      MyMail.From = new MailAddress("", "");  
      MyMail.To.Add(new MailAddress(""));  
      MyMail.Subject = Mailtitle;  
      MyMail.Body = MailCon;  
      MyMail.IsBodyHtml = false;  
      SmtpClient smtpclient = new SmtpClient();  
      smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;  
      smtpclient.Host = "";  
      smtpclient.Credentials = new System.Net.NetworkCredential(MailFrom, MailPwd);  
      smtpclient.Send(MyMail);  
      }  
    jmail.Message Jmail = new jmail.Message();  
      DateTime t = DateTime.Now;  
      String Subject = "";  
      String body = "";  
      String FromEmail = "";  
      String ToEmail = "";  
      Jmail.Charset = "GB2312";  
      Jmail.ContentType = "text/html";  
      Jmail.AddRecipient(ToEmail, "", "");  
      Jmail.From = FromEmail;  
      Jmail.MailServerUserName = "";  
      Jmail.MailServerPassWord = "";  
      Jmail.Subject = Subject;  
      Jmail.ContentType="text/html";  
      Jmail.Body = body + t.ToString();  
      Jmail.Send("", false);  
      Jmail.Close();  
     
     
      

  7.   

    建议使用 163邮箱试一试!
    using System.Net.Mail;
    public static bool SendMail(string messTo,string messBody)
            {
                MailMessage mess = new MailMessage();
                mess.From = new MailAddress("[email protected]", "报警系统");//发件人
                mess.Subject = "报警系统";//主题
                mess.IsBodyHtml = true;//允许HTML
                mess.BodyEncoding = System.Text.Encoding.UTF8;//编码
                mess.Body = messBody;
                SmtpClient client = new SmtpClient();//new 出 客服端的 smtp
                client.Host = "smtp.163.com";
                client.Credentials = new System.Net.NetworkCredential("mmm306306", "xxxxxxxxx");//需要发件人的账号 密码
                mess.To.Add(new MailAddress(messTo));//收件人 数组(可以群发)
                try
                {
                    client.Send(mess);
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }_________________________________________________________________________________________MailMessage mail = new MailMessage(); 
    mail.To = "[email protected]"; 
    mail.From = "[email protected]"; 
    mail.Subject = "this is a test email."; 
    mail.Body = "Some text goes here"; 
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authenticationmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "abc"); //set your username heremail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "your password"); //set your passwordhere SmtpMail.SmtpServer = "smtp.126.com"; //your real server goes here 
    SmtpMail.Send( mail );
      

  8.   

    非常感谢啊,现在163是默认开启smtp/pop3的,不过你不说我不知道,用七楼的方法实现了。