您当前的位置: 首页 >  c#

暂无认证

  • 0浏览

    0关注

    101061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

[C#]邮件发送

发布时间:2010-06-20 10:42:00 ,浏览量:0

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 {}

    }

}

////// 发送邮件方法
    //////邮件地址///主题///内容///发送成功/// 创建日期: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
关注
打赏
1655516835
查看更多评论
立即登录/注册

微信扫码登录

0.0517s