• 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

  • 相关阅读:
    多线程(5)async&await
    多线程(4)Task
    多线程(3)ThreadPool
    多线程(2)Thread
    多线程(1)认识多线程
    泛型
    反射(4)反射性能问题:直接调用vs反射调用
    反射(3)反射应用:一个插件项目
    反射(2)使用反射
    反射(1)认识反射
  • 原文地址:https://www.cnblogs.com/zhuzhiyuan/p/2024502.html
Copyright © 2020-2023  润新知