Я пытаюсь добавить FileAttachment
к сообщению.К сожалению message.Attachments.AddFileAttachment()
просит путь, которого у меня нет.У меня есть FileAttachment
прямо из другого письма.
Здесь я получаю вложение:
EmailMessage oldEmailMessage = EmailMessage.Bind(service, olderSoxMail.Id);
// load attachments
FileAttachment fileAttachment = newEmailMessage.Attachments[0] as FileAttachment;
fileAttachment.Load();
Здесь я пытаюсь прикрепить вложение к письму
public static void ComposeEmail(string recipient, string subject, string body, FileAttachment[] attachment = null)
{
var map = new Dictionary<char, string>() {
{ 'ä', "ae" },
{ 'ö', "oe" },
{ 'ü', "ue" },
{ 'Ä', "Ae" },
{ 'Ö', "Oe" },
{ 'Ü', "Ue" },
{ 'ß', "ss" }
};
recipient = recipient.Aggregate(
new StringBuilder(),
(sb, c) =>
{
string r;
if (map.TryGetValue(c, out r))
return sb.Append(r);
else
return sb.Append(c);
}).ToString();
EmailMessage message = new EmailMessage(service);
message.Subject = subject;
message.Body = body;
message.ToRecipients.Add(recipient);
foreach (FileAttachment attach in attachment)
{
// COMPILER ERROR HERE: Cannot Convert from FileAttachment to Path (string)
message.Attachments.AddFileAttachment(attach);
// END ERROR
}
message.SendAndSaveCopy();
}
Вы знаете, как я могу добавить FileAttachment
?