SHOW:
|
|
- or go back to the newest paste.
1 | using System.Net; | |
2 | using System.Net.Mail; | |
3 | using System; | |
4 | using System.Collections.Generic; | |
5 | using System.ComponentModel; | |
6 | using System.Data; | |
7 | using System.Drawing; | |
8 | using System.Linq; | |
9 | using System.Text; | |
10 | using System.Threading.Tasks; | |
11 | using System.Windows.Forms; | |
12 | ||
13 | namespace תוכנה_מצויינת_למיקמק_עובדת | |
14 | { | |
15 | public partial class Form1 : Form | |
16 | { | |
17 | public Form1() | |
18 | { | |
19 | InitializeComponent(); | |
20 | } | |
21 | ||
22 | private void button1_Click(object sender, EventArgs e) | |
23 | { | |
24 | using System.Net; | |
25 | using System.Net.Mail; | |
26 | ||
27 | - | class Program |
27 | + | string smtpAddress = "smtp.gmail.com"; |
28 | int portNumber = 587; | |
29 | - | static void Main() |
29 | + | bool enableSSL = true; |
30 | ||
31 | - | string smtpAddress = "smtp.mail.yahoo.com"; |
31 | + | string emailFrom = "[email protected]"; |
32 | - | int portNumber = 587; |
32 | + | string password = "*******"; |
33 | - | bool enableSSL = true; |
33 | + | string emailTo = "[email protected]"; |
34 | string subject = "Hello"; | |
35 | - | string emailFrom = "[email protected]"; |
35 | + | string body = "Hello, I'm just writing this to say Hi!"; |
36 | - | string password = "*******"; |
36 | + | |
37 | - | string emailTo = "[email protected]"; |
37 | + | using (MailMessage mail = new MailMessage()) |
38 | - | string subject = "Hello"; |
38 | + | |
39 | - | string body = "Hello, I'm just writing this to say Hi!"; |
39 | + | mail.From = new MailAddress(emailFrom); |
40 | mail.To.Add(emailTo); | |
41 | - | using (MailMessage mail = new MailMessage()) |
41 | + | mail.Subject = subject; |
42 | mail.Body = body; | |
43 | - | mail.From = new MailAddress(emailFrom); |
43 | + | mail.IsBodyHtml = true; |
44 | - | mail.To.Add(emailTo); |
44 | + | // Can set to false, if you are sending pure text. |
45 | - | mail.Subject = subject; |
45 | + | |
46 | - | mail.Body = body; |
46 | + | //mail.Attachments.Add(new Attachment("C:\\SomeFile.txt")); |
47 | - | mail.IsBodyHtml = true; |
47 | + | //mail.Attachments.Add(new Attachment("C:\\SomeZip.zip")); |
48 | - | // Can set to false, if you are sending pure text. |
48 | + | |
49 | using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) | |
50 | - | mail.Attachments.Add(new Attachment("C:\\SomeFile.txt")); |
50 | + | |
51 | - | mail.Attachments.Add(new Attachment("C:\\SomeZip.zip")); |
51 | + | smtp.Credentials = new NetworkCredential(emailFrom, password); |
52 | smtp.EnableSsl = enableSSL; | |
53 | - | using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber)) |
53 | + | smtp.Send(mail); |
54 | - | { |
54 | + | |
55 | - | smtp.Credentials = new NetworkCredential(emailFrom, password); |
55 | + | |
56 | - | smtp.EnableSsl = enableSSL; |
56 | + | |
57 | - | smtp.Send(mail); |
57 | + | |
58 | - | } |
58 | + |