-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
44 lines (38 loc) · 1.42 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Net.Mail;
using System.Windows.Forms;
namespace EmailSender
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnsend_Click(object sender, EventArgs e)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com",587);
MailMessage message = new MailMessage();
message.From = new MailAddress("youremail@gmail.com"); // Sending Email
message.To.Add(txtreciever.Text); // To emailid
message.Subject = txtsubject.Text; // Subject
message.Body = txtbody.Text; // Body
client.UseDefaultCredentials = false;
client.EnableSsl = true; // Enabling secured Connection
client.Credentials = new System.Net.NetworkCredential("youremail@gmail.com", "yourPassword"); // Credential of gmail
Cursor.Current = Cursors.WaitCursor;
client.Send(message); //Sending...
MessageBox.Show("Email Sent Successfully.");
Cursor.Current = Cursors.Default;
message = null; // Free the memory
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}