zoukankan      html  css  js  c++  java
  • 发送邮件 html格式

    下面黄色代码为实现发送邮件

    FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/productConsultAnwser.html"), FileMode.OpenOrCreate, FileAccess.Read);
                                    StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                                    string strTemp = sr.ReadToEnd();
                                    sr.Close();
                                    fs.Close();
                                    //if (queryTemp.spec_name1 == "" && queryTemp.spec_name2 == "")
                                    //{
                                    //    product_name = queryTemp.brand_name + queryTemp.product_name;
                                    //}
                                    //else
                                    //{
                                    //    product_name = queryTemp.brand_name + queryTemp.product_name + "(" + queryTemp.spec_name1 + "  " + queryTemp.spec_name2 + ")";
                                    //}
                                    product_name = queryTemp.product_name;
                                    strTemp = strTemp.Replace("{{$username$}}", userName);
                                    strTemp = strTemp.Replace("{{$productName$}}", product_name);
                                    strTemp = strTemp.Replace("{{$consultInfo$}}", consultInfo);
                                    strTemp = strTemp.Replace("{{$consultAnwser$}}", answerInfo);
                                    strTemp = strTemp.Replace("{{$productUrl$}}", productUrl);
                                    sendmail(EmailFrom, FromName, userEmail, userName, EmailTile, strTemp, "", SmtpHost, Convert.ToInt32(SmtpPort), EmailUserName, EmailPassWord);



      public bool sendmail(string sfrom, string sfromer, string sto, string stoer, string sSubject, string sBody, string sfile, string sSMTPHost, int sSMTPPort, string sSMTPuser, string sSMTPpass)
            {
                ////设置from和to地址
                MailAddress from = new MailAddress(sfrom, sfromer);
                MailAddress to = new MailAddress(sto, stoer);

                ////创建一个MailMessage对象
                MailMessage oMail = new MailMessage(from, to);
                //// 添加附件
                if (sfile != "")
                {
                    oMail.Attachments.Add(new Attachment(sfile));
                }
                ////邮件标题
                oMail.Subject = sSubject;
                ////邮件内容
                //oMail.Body = sBody;
                AlternateView htmlBody = AlternateView.CreateAlternateViewFromString(sBody, null, "text/html");
                oMail.AlternateViews.Add(htmlBody);
                ////邮件格式
                oMail.IsBodyHtml = true;
                ////邮件采用的编码
                oMail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312");
                ////设置邮件的优先级为高
                oMail.Priority = MailPriority.Normal;
                ////发送邮件
                SmtpClient client = new SmtpClient();
                ////client.UseDefaultCredentials = false;
                client.Host = sSMTPHost;
                client.Port = sSMTPPort;
                client.Credentials = new NetworkCredential(sSMTPuser, sSMTPpass);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                try
                {
                    client.Send(oMail);
                    return true;
                }
                catch (Exception ex)
                {
                 
                }
                finally
                {
                    ////释放资源
                    oMail.Dispose();
                }

            }



  • 相关阅读:
    Unity 类似FingerGestures 的相机跟随功能
    protected 学习
    Unity 学习Json篇
    Unity 动态加载 Prefab
    iTween基础之iTweenPath(自定义路径移动)
    Unity连Photon服务器入门详解
    如何用unity3d实现发送带附件的邮件
    【转】【风宇冲】Unity3D教程宝典之Web服务器篇
    unity Editor编辑器插件脚本学习
    收集整理Android开发所需的Android SDK、开发中用到的工具
  • 原文地址:https://www.cnblogs.com/sdya/p/4413750.html
Copyright © 2011-2022 走看看