[C#]邮件发送

    public static void mailadd(string mailto, string mailsubject, string mailbody, string attech)//创建Mail,填入发送人,主题,內容
    {
        {
        MailMessage mlMsg = new MailMessage();        
        //处理多个收件人
         string[] toArray = mailto.Split(',');
        foreach (string i in toArray)
        {
           mlMsg.To.Add(new MailAddress(i));
        }

        mlMsg.Subject = mailsubject;
        mlMsg.Body = mailbody;
        mlMsg.IsBodyHtml = true;
        mlMsg.From = new MailAddress("workflowweb@shinhint.gd.cn","Automatic(自动化)");


        //附件
         if (attech != "") 
        {
            string[] attArray = attech.Split(',');
            foreach (string a in attArray)
            {
                string strFilePath = @a;
                Attachment attachment1 =
                        new Attachment(strFilePath);
                attachment1.Name = System.IO.Path.GetFileName(strFilePath);
                //attachment1.NameEncoding = Encoding.UTF8;
                attachment1.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;

                内嵌式附件
                //attachment1.ContentDisposition.Inline = true;
                //attachment1.ContentDisposition.DispositionType =
                //   System.Net.Mime.DispositionTypeNames.Inline;

                //attachment1.
                mlMsg.Attachments.Add(attachment1);
            }
        }

        SmtpClient smtpClient = new SmtpClient("mailshinhint.shinhint");
        smtpClient.Credentials = new NetworkCredential("workflowweb", "1234");
            
        //smtpClient.Timeout = 1000;
            
        smtpClient.EnableSsl =false;
        smtpClient.Send(mlMsg);
        }
       // catch {}

    }

}

/// <summary>
    /// 发送邮件方法
    /// </summary>
    /// <param name="m_add">邮件地址</param>
    /// <param name="m_sub">主题</param>
    /// <param name="m_sub">内容</param>
    /// <returns>发送成功</returns>
    /// 创建日期:2008-7-20
    /// 创建人:龚德辉
    public static Boolean new_mail(string m_add, string m_sub, string m_body)//创建Mail,填入发送人,主题,內容
    {
        try
        {
            MailMessage msz = new MailMessage();//建立邮件对象   
            msz.To = m_add;     //string   email是对方邮箱地址  
            //msz.From = "workflow@solartech.com.cn";
            msz.From = "workflowweb@shinhint.gd.cn"; //可以是任意可用smtp地址  
            msz.Subject = m_sub;   //邮件标题   
            msz.Body = m_body;
            msz.BodyFormat = MailFormat.Html;
            msz.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");//是否需要验证,一般是要的   
            msz.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "workflowweb");//自己邮箱的用户名   
            msz.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "1234");//自己邮箱的密码 
            SmtpMail.SmtpServer = "mailshinhint.shinhint";// 服务器地址
            SmtpMail.Send(msz);   //发送 
            return true;
        }
        catch { return false; }
    }
    #endregion

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

厦门德仔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值