好的我在这里试图向用户发送有关无效附件的电子邮件.我正在收集上一个函数中的无效附件名称(字符串)列表,然后我尝试发送一封电子邮件,列出所有被视为无效的附件.不知道如何处理这种情况.我有以下示例
List<string> invalidType = new List<string>();
if (invalidType != null)
{
emailInvalidBody = new ItemBody
{
Content = " Expense attachements recieved with subject line [ "
+ email.Subject
+ " ] sent at [ "
+ email.DateTimeReceived.Value.DateTime.ToLocalTime()
+ " ] had the following invalid attachments ["
+ invalidType
+ "]. Please make sure all attachment's are images or PDF's.",
};
}
List<Recipient> emailInvalidRecipients = new List<Recipient>();
emailInvalidRecipients.Add(new Recipient
{
EmailAddress = new EmailAddress
{
Address = email.Sender.EmailAddress.Address
}
});
Message invalidEmailMessage = new Message
{
Subject = "Invalid Expenses",
Body = emailInvalidBody,
ToRecipients = emailInvalidRecipients
};
starBox.Users[EMAILBOX].SendMailAsync(invalidEmailMessage, false).Wait();
Run Code Online (Sandbox Code Playgroud)
我的最终目标是建立一个可以执行以下操作的电子邮件正文
"在主题行收到的费用附件在2016年1月8日8:00发送的主题有以下无效附件[invalidattachment1 invalidattachment2 invalidattachment3 invalidattachment4].请确保所有附件都是图片或PDF.",
使用string.Join List<string>在列表中转换所有连接在一起的项目
List<string> invalidType = new List<string>();
.....
// Probably you don't need to check for null but for element count.
// However it doesn't hurt to be a little defensive...
if (invalidType != null && invalidType.Count > 0)
{
string attachments = string.join(",", invalidType);
emailInvalidBody = new ItemBody
{
Content = " Expense attachments received with subject line [ " +
email.Subject + " ] sent at [ " +
email.DateTimeReceived.Value.DateTime.ToLocalTime() +
" ] had the following invalid attachments [" +
attachments + "]. Please make sure all " +
" attachment's are images or PDF's.",
};
}
Run Code Online (Sandbox Code Playgroud)