我在使用C#向多个电子邮件地址发送电子邮件时遇到问题。
var email = new EmailMessageApiDto
{
SendTo = input.SendTo,
Body = input.Body,
MailVariables = new List<VariableDictionaryDto>(),
Recipient = new EmailRecipientDto
{
EmailAddress = input.SendTo,
FirstName = input.SendTo.Split('@').First(),
LastName = input.SendTo.Split('@').Last()
},
SendDateTime = Clock.Now,
Subject = input.Subject,
Sender = new EmailSenderDto
{
EmailAddress = account.SmtpSettings.DefaultSenderAddress,
FirstName = account.SmtpSettings.DefaultSenderDisplayName.Split(' ').First(),
LastName = account.SmtpSettings.DefaultSenderDisplayName.Split(' ').Last()
},ReplyTo = account.SmtpSettings.DefaultSenderAddress
};
我是否需要为“;”做一些逃脱分隔符:如果是,怎么做?
答案 0 :(得分:0)
I am not familiar with the classes you are using, but you can send an e-mail to multiple users using the .Net Framework
using System.Net.Mail;
public static void SendMessage(string[] sendTo, string sendFrom, string subject, string messageText, string cc, string attachmentPath)
{
// Create a new message copying the person who sent it
using (var message = new MailMessage(sendFrom, sendFrom, subject, messageText))
{
// Add each email address to send to.
foreach (string s in sendTo)
message.To.Add(new MailAddress(s));
// Add cc to the message if not blank.
if (!String.IsNullOrEmpty(cc))
message.CC.Add(new MailAddress(cc));
if (!String.IsNullOrEmpty(attachmentPath))
message.Attachments.Add(new Attachment(attachmentPath));
// Send mail through smtp server.
using (var client = new SmtpClient("yoursmtpserverhere"))
client.Send(message);
}
}