天天看点

谈谈发送邮件(C#/Asp.net)功能

<script type="text/javascript"> </script> <script type="text/javascript"> </script>

之前,一位同学向我请教发送邮件功能,由于好长时间没去碰C#所以多多少少都忘记一点,然后今天没事,就写了一个demo测

试了一下,嘿嘿,被我调试成功能,不过在成功之前,查看了资料,网上写得都不太清楚而且有好多都是没用的(出现错误,编

译不成功的),于是自己写了个,,希望对自己和大家都有用,,

static void Main(string[] args)

{

string Poster = "[email protected]"; //发送者邮箱地址

string PosterPwd = "xxx";//发送者邮箱密码

System.Net.Mail.SmtpClient client = new SmtpClient("smtp.139.com");

client.UseDefaultCredentials = false;

client.Credentials = new System.Net.NetworkCredential(Poster, PosterPwd);

client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(Poster, "[email protected]", "xx", "测试邮件");

System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment("c://log.log");

message.Attachments.Add(attachment);

message.BodyEncoding = System.Text.Encoding.UTF8;

message.IsBodyHtml = true;

try

{

client.Send(message);

Console.WriteLine("发送成功" );

Console.ReadLine();

}

catch (Exception ex)

{

Console.WriteLine("失败"+ex.Message);

Console.WriteLine(""+ex.StackTrace);

Console.ReadLine();

}

}

注:由于126的邮件服务不能用,所以就换成139的服务器了,这点请大家注意!!!!

对于以上功能,只能实现简单的邮件发送功能,具体以后用到再谈,现在只写这么多,请大家见谅!!!!

===============================注意 ==================================================

以上写的有些大致,不过重点都已讲到,如果有不明白请与我联系:

网站:     http://chenhuzi.gicp.net 

QQ :     415845188

Email:   [email protected]

MSN:      [email protected]

淘宝站: chenhuzi.taobao.com

Mobile: (通过以上方式获取吧!)

版权所有,转载时请注明出处,谢谢配合!!!