这几天开发的从数据库抓起数据处理完已邮件发出来,只实现的To的个人的发送,To的群组,CC的个人和群组,BCC的个人和群组都没有成功。试了好久,感觉是Exchange服务器配置的问题,但又无法访问Exchange的服务器,所以暂时先放弃完善。

测试的过程中了解好多只是,现在记录一下

下面的代码示例演示如何通过使用发送一封电子邮件SmtpClient, MailAddress,和MailMessage类。

public static void CreateCopyMessage(string server)
{
    MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");
    MailAddress to = new MailAddress("jane@contoso.com", "Jane Clayton");
    MailMessage message = new MailMessage(from, to);
    // message.Subject = "Using the SmtpClient class.";
    message.Subject = "Using the SmtpClient class.";
    message.Body = @"Using this feature, you can send an email message from an application very easily.";
    // Add a carbon copy recipient.
    MailAddress copy = new MailAddress("Notification_List@contoso.com");
    message.CC.Add(copy);
    SmtpClient client = new SmtpClient(server);
    // Include credentials if the server requires them.
    client.Credentials = CredentialCache.DefaultNetworkCredentials;
    Console.WriteLine("Sending an email message to {0} by using the SMTP host {1}.",
         to.Address, client.Host);

   try {
      client.Send(message);
    }
    catch (Exception ex) {
      Console.WriteLine("Exception caught in CreateCopyMessage(): {0}", 
                  ex.ToString() );
      }
  }

MailMessage类来存储地址信息的电子邮件。

DisplayName可以包含非 ASCII 字符,如果对它们进行编码。

MailAddress类支持以下邮件地址格式:

  • DisplayName未设置,这是生成的邮件地址格式。

  • DisplayName设置,这是生成的格式。

  • 如果这些信息将不包含。

  • DisplayName为display name <user@host>,如果这些信息将不包含。

  • DisplayName属性。

  • 例如 user...name..@host

  • 例如 <user@[my domain]>

  • 在传输之前会删除注释。

允许以下邮件地址:

"John, Doe" <user@host>, "Bob, Smith" <user2@host>

不允许以下邮件地址:

John, Doe <user@host>, Bob, Smith <user2@host>

允许以下邮件地址:

"John \"Jr\" Doe" <user@host>

"\"John \\\"Jr\\\" Doe\" <user@host>"

不允许以下邮件地址:

"John "Jr" Doe" <user@host>

例如:

(non comment) unquoted display (non comment) name (non comment) <user@host>

MailAddress类接受有效、 其他邮件服务器将不会接受邮件地址的邮件地址。

MailAddress类不支持以下邮件地址格式:

  • 组,如在 RFC 2822 第 3.4 IETF 发布的节中定义。

https://docs.microsoft.com/zh-cn/dotnet/api/system.net.mail.mailaddress?view=netframework-4.7.2

MailMessage.CC

https://docs.microsoft.com/zh-cn/dotnet/api/system.net.mail.mailmessage.cc?view=netframework-4.7.2#System_Net_Mail_MailMessage_CC

MailMessage

https://docs.microsoft.com/zh-cn/dotnet/api/system.net.mail.mailmessage?f1url=https%3A%2F%2Fmsdn.microsoft.com%2Fquery%2Fdev15.query%3FappId%3DDev15IDEF1%26l%3DZH-CN%26k%3Dk(System.Net.Mail.MailMessage);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.0);k(DevLang-csharp)%26rd%3Dtrue&view=netframework-4.7.2

 

相关文章:

  • 2022-12-23
  • 2021-12-03
  • 2022-02-02
  • 2022-12-23
  • 2021-08-10
  • 2021-12-11
  • 2022-01-04
  • 2021-08-30
猜你喜欢
  • 2021-08-05
  • 2022-12-23
  • 2021-04-05
  • 2021-12-16
  • 2021-09-12
相关资源
相似解决方案