文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>发送Email 附件打包,

发送Email 附件打包,

时间:2011-05-25  来源:web开发

  MailAddress fromAddress = new MailAddress("[email protected]", "明道", Encoding.GetEncoding("utf-8"));

        StringBuilder sb = new StringBuilder("");

              //发送者 

       System.Net.Mail.MailAddress toAddress = new System.Net.Mail.MailAddress(user.Email);


        MailMessage message = new MailMessage(fromAddress, toAddress);

        message.Subject = "管理员" + fromUser.Fullname + "发布的通告";

        message.Body = sb.ToString(); 

       message.IsBodyHtml = true; 

       message.BodyEncoding = Encoding.GetEncoding("utf-8");

        message.SubjectEncoding = Encoding.GetEncoding("utf-8");

        if (!string.IsNullOrEmpty(filePath))

        {

            //附件

            System.Net.Mail.Attachment mailAttachment  = new System.Net.Mail.Attachment(filePath);

            if (mailAttachment != null)

                message.Attachments.Add(mailAttachment);

            //foreach (string attachment in attachments)  //循环附件

            //{

            //    System.Net.Mail.Attachment newAttachment = new System.Net.Mail.Attachment(attachment);

            //    if (newAttachment != null)

            //        message.Attachments.Add(newAttachment);

            //}

        }

  try

      {

            MailAddress from = new MailAddress(message.From.Address, message.From.DisplayName, Encoding.GetEncoding("utf-8"));

            message.From = from;

            message.IsBodyHtml = isBodyHtml;

            message.BodyEncoding = Encoding.GetEncoding("utf-8");

            message.SubjectEncoding = Encoding.GetEncoding("utf-8");
            SmtpClient client = new SmtpClient("mail.meihua.info");

            client.Credentials = new System.Net.NetworkCredential("sender", "111111");
            client.Send(message);

        } 

       catch {}

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载