用C#写代码实现邮件发送的效果

解决方案 »

  1.   

    using System.Net.Mail;
    using System.Net;            MailAddress MailFrom = new MailAddress("*****@163.com");
                MailAddress MailTo = new MailAddress("*****@gmail.com");
                MailMessage Mails = new MailMessage(MailFrom, MailTo);
                Mails.Subject = "Kevin Test Mail";
                Mails.IsBodyHtml = true;
                Mails.Body = " this is a test mail whitch used the Net2.0";
                Attachment AFile = new Attachment(@"C:\MyLog.txt");
                Mails.Attachments.Add(AFile);
                SmtpClient Smtps = new SmtpClient("smtp.163.com");
                Smtps.Credentials = new NetworkCredential("****","****");
                try
                {
                    Smtps.Send(Mails);
                    MessageBox.Show("发送成功");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("发送出错,错误信息如下:" + ex.Message);
                }
      

  2.   


    /// <summary>
            /// 发送邮件
            /// </summary>
            internal void Send()
            {
                System.Web.Mail.MailMessage mailmessage = new MailMessage();            mailmessage.From = "[email protected]";
                mailmessage.To = "张大伟";
                mailmessage.Subject = "我是主题";
                mailmessage.Body = "我是内容";
                mailmessage.Cc = "张明";
                mailmessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");            mailmessage.Fields.Add
                ("http://schemas.microsoft.com/cdo/configuration/sendusername",myEmailUserName);
                //自己邮箱的用户名 
                mailmessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", myEmailPassword);
                //自己邮箱的密码 
                System.Web.Mail.SmtpMail.SmtpServer ="smtp.163.com"; //SMTP Server
                System.Web.Mail.SmtpMail.Send(mailmessage);        }
      

  3.   

    当我把163的邮箱服务器地址换成 smtp.163.com.cn 后 可以发送了 但是那些邮件却变成垃圾邮件被拦截 而且我原本定义的内容面目全非