简体   繁体   English

将收件人 email 地址添加到 email 正文

[英]Adding the recipient email address to the email body

I'm using C# code with basic System.Net.Mail.我将 C# 代码与基本 System.Net.Mail 一起使用。 SmtpClient to send email to recipients. SmtpClient将 email 发送给收件人。

In the email's body, I need to add the email address for each recipient, Is there is a way to do so in one email to multiple recipients?在电子邮件的正文中,我需要为每个收件人添加 email 地址,有没有办法在一个 email 中为多个收件人添加地址?

//basic settings    
MailMessage mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.gmail.com";
mail.Subject = "this is a test email.";

//relevent part
msgClient.To.Add(user1@hotmail.com);
msgClient.To.Add(user2@hotmail.com);
msgClient.To.Add(user3@hotmail.com);
mail.Body = "I need to put here the customer's Email Address without sending multiple emails";

client.Send(mail);

this is not possible due to SMTP protocol limitations if you want to do this, you probably should send your emails one by one.由于 SMTP 协议限制,这是不可能的,如果您想这样做,您可能应该一一发送您的电子邮件。 nonetheless, it is best if you change the format of your emails so you don't need to include such data in the message body.尽管如此,最好更改电子邮件的格式,这样您就不需要在邮件正文中包含此类数据。


ps: System.Net.Mail.SmtpClien is deprecated use mailkit instead, the APIs are the same, so you don't need to change your code, you just need to install it via NuGet and then change the reference from System.Net.Mail.SmtpClien to MailKit.Net.Smtp.SmtpClient ps: System.Net.Mail.SmtpClien已弃用,请改用mailkit ,API 相同,因此您无需更改代码,只需通过 NuGet 安装它,然后从System.Net.Mail.SmtpClienMailKit.Net.Smtp.SmtpClient

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM