C#使用smtp发送邮件

使用新浪邮件成功发送, 腾讯邮箱等由于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();
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值