zoukankan      html  css  js  c++  java
  • C#发送邮件,生成VCard

    #region 发送邮件

    /// <summary>
    /// 系统发送
    /// </summary>
    public static bool AutoSendMail(MailAddress toAddress, string bodyHtml, string subject)
    {
      bool flag = false;

      try
      {
        MailAddress fromAddress = new MailAddress("sender@meihua.info", "明道", Encoding.GetEncoding("utf-8"));
        MailMessage message = new MailMessage(fromAddress, toAddress);
        message.Subject = subject;
        message.Body = bodyHtml;
        message.IsBodyHtml = true;
        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);
        flag = true;
      }
      catch
      {

      }

      return flag;
    }
    /// <summary>
    /// 自定义发送
    /// </summary>
    public static bool SendMail(MailMessage message, bool isBodyHtml)
    {
      bool flag = false;

      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);

        flag = true;
      }
      catch
      {

      }

      return flag;
    }

    #endregion

    #region 生成VCard

    /// <summary>
    /// 生成VCard
    /// </summary>
    public static string CreateVCard(string fullName, string company, string job, string workPhone, string mobilePhone, string email, string workAddress)
    {
      string httpPath = "../tempfiles/";
      string absolutePath = HttpContext.Current.Server.MapPath(httpPath);
      string folderName = Function.CreateRandomDirectoryFolder(absolutePath);
      string fileName = absolutePath + folderName + "\\" + fullName + ".vcf";
      System.IO.StreamWriter stringWrite = new System.IO.StreamWriter(fileName, true, System.Text.Encoding.Default);
      stringWrite.WriteLine("BEGIN:VCARD");
      stringWrite.WriteLine("VERSION:2.1");
      stringWrite.WriteLine("FN:" + fullName);
      stringWrite.WriteLine("ORG;CHARSET=gb2312:" + company);
      stringWrite.WriteLine("TITLE:" + job);
      stringWrite.WriteLine("TEL;WORK;VOICE:" + workPhone);
      stringWrite.WriteLine("TEL;CELL;VOICE:" + mobilePhone);
      stringWrite.WriteLine("EMAIL;PREF;INTERNET:" + email);
      stringWrite.WriteLine("ADR;WORK:;;" + workAddress + ";;;" + string.Empty);
      stringWrite.WriteLine("END:VCARD");
      stringWrite.Close();
      stringWrite.Dispose();
      string httpURL = httpPath + folderName + "\\" + fullName + ".vcf";

      return httpURL;
    }

    #endregion

  • 相关阅读:
    iOS new Date() 报invalid Date
    Windows查找端口对应进程
    Dbvisualizer Free版本无sql自动提示功能解决方案
    Docker
    更换k8s集群,或者创建集群使用用户不对,导致ranchar无法显示容器处理
    linux下mysql5.7.30安装
    ansible 使用redis缓存
    tr命令
    ipvsadm安装配置NAT
    2019新电脑主板安装win10系统
  • 原文地址:https://www.cnblogs.com/zhuzhiyuan/p/2024502.html
Copyright © 2011-2022 走看看