日期:2014-05-18  浏览次数:21245 次

winform 中发送邮件出错
winform程序,总是报sendusing 配置值无效,是什么原因?代码如下:
  还有请问怎么在winform中写接受邮件
 try
  {
  CDO.Message objMsg = new CDO.Message();
  objMsg.From = "heqiangl@163.com; //此处邮件名可以换为自己的
  objMsg.To = "heqiangl@163.com"; //此处邮件名可以换为自己的

  objMsg.Subject = "mail Subject test"; 
  objMsg.HTMLBody = "测试成功@";
  objMsg.Send();
  }
  catch
  {
   
  } 


------解决方案--------------------
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();

client.Host = "mail.bcl.com.cn";
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("zhangbo@mail.bcl.com.cn", "12321232");
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("zhangbo@mail.bcl.com.cn", "zhangbo@mail.bcl.com.cn");
message.Subject = "测试aa";
message.Body = "<html>用自己写的asdfasdf软件发的邮件!<image src=1.jpg></image></html>";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
message.Attachments.Add(new Attachment("C:\\1.jpg"));

////添加附件
//Attachment data = new Attachment(@"附件地址如:e:\a.jpg", System.Net.Mime.MediaTypeNames.Application.Octet);
//message.Attachments.Add(data);








try
{
client.Send(message);

}
catch (Exception ex)
{ }