SHOW:
|
|
- or go back to the newest paste.
1 | - | using System.Net ; |
1 | + | using System.Net; |
2 | using System.Net.Mail; | |
3 | ||
4 | class Program | |
5 | { | |
6 | static void Main() | |
7 | { | |
8 | string smtpAddress = "smtp.mail.yahoo.com"; | |
9 | int portNumber = 587; | |
10 | bool enableSSL = true; | |
11 | ||
12 | string emailFrom = "oded4664@gmail.com"; | |
13 | string password = "*******"; | |
14 | string emailTo = "oded4664@gmail.com"; | |
15 | string subject = "Hello"; | |
16 | string body = "Hello, I'm just writing this to say Hi!"; | |
17 | ||
18 | using (MailMessage mail = new MailMessage()) | |
19 | { | |
20 | mail.From = new MailAddress(emailFrom); | |
21 | mail.To.Add(emailTo); | |
22 | mail.Subject = subject; | |
23 | mail.Body = body; | |
24 | mail.IsBodyHtml = true; | |
25 | // Can set to false, if you are sending pure text. | |
26 | ||
27 | mail.Attachments.Add(new Attachment("C:\\SomeFile.txt")); | |
28 | mail.Attachments.Add(new Attachment("C:\\SomeZip.zip")); | |
29 | ||
30 | using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) | |
31 | { | |
32 | smtp.Credentials = new NetworkCredential(emailFrom, password); | |
33 | smtp.EnableSsl = enableSSL; | |
34 | smtp.Send(mail); | |
35 | } | |
36 | } | |
37 | } | |
38 | } |