Csharp/C Sharp by API/System.Net.Mail/Attachment

Материал из .Net Framework эксперт
Версия от 12:12, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

new Attachment

  
using System;
using System.Net;
using System.Net.Mail;
class MainClass
{
    public static void Main(string[] args)
    {
        SmtpClient client = new SmtpClient("mail.somecompany.ru", 25);
        client.Credentials =new NetworkCredential("user@somecompany.ru", "password");
        using (MailMessage msg = new MailMessage())
        {
            msg.From = new MailAddress("author@aaa.ru");
            msg.Subject = "HI";
            msg.Body = "A message";
            msg.Attachments.Add(new Attachment("c:\\test.txt", "text/plain"));
            msg.Attachments.Add(new Attachment("C:\\test.exe", "application/octet-stream"));
            msg.To.Add(new MailAddress("message to address"));
            client.Send(msg);
        }
    }
}