使用新浪邮件成功发送, 腾讯邮箱等由于SSL等原因发送失败.
注意邮件主题,邮件内容,太简单有可能被当作垃圾邮件!
测试发现虽然有可能被当作垃圾邮件,但是还是可以从新浪邮箱的系统退信中找到发送的邮件(用outlook express打开查看.eml邮件文件内容就行了),达到自动发送邮件给自己的目的,如果要发送给别人,那就要看运气了!
using System;
using System.Collections.Generic;using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
MailMessage mm = new MailMessage("from@sina.cn", "to@hotmail.com", "邮件主题", "邮件内容");
mm.IsBodyHtml = true;
mm.BodyEncoding = System.Text.Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
mm.Attachments.Add(new Attachment("E:\\test.txt"));
SmtpClient sc = new SmtpClient();
NetworkCredential nc = new NetworkCredential();
nc.UserName = "from@sina.cn";
nc.Password = "password";
sc.UseDefaultCredentials = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Credentials = nc;
sc.Host = "smtp.sina.cn";
sc.Port = 587;
sc.EnableSsl = true;
sc.Send(mm);
Console.WriteLine("邮件发送成功!");
Console.Read();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.Read();
}
}
}
}