Initial chamber
Step 1: Open Your Visual Studio 2010, Go to File, New, Projects, then under Visual C# select Windows.
You can change the name of the project and browse your project to different location too. And then press OK.
Design chamber
Step 2: Now open your Form1.cs file, where we will create our design for sending email to gmail. We will drag 3 labels, 3 textboxes and one button from toolbox to Form1.cs. You will see your Form look like this.
Code chamber
Right click on the blank part of Form1.cs, then click View Code. You will enter in the code part of the form. Write the following code and then Press F5 to run the project.
For GmailSend.dll file - -> https://gmailsend.codeplex.com/
Add some of the namespaces for sending Gmail.
If you can’t find these namespaces in the intellisense, then in the Solution Explorer - Right Click, Add References. In Add References, Browse and Find GmaiSend.dll that you had downloaded from the above link.
Add References:
Code chamber
Open your Form1.cs file where you have to write the code for sending Gmail.
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using GmailSend;
-
-
- namespace WindowsFormsApplication2
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- gmail gmlsnd = new gmail();
- gmlsnd.auth("your emailid", "your password");
- gmlsnd.To = textBox1.Text;
-
-
- gmlsnd.Subject = textBox2.Text;
- gmlsnd.Message = textBox3.Text;
-
- gmlsnd.Priority = 1;
- gmlsnd.send();
-
- MessageBox.Show("Your Mail is sended");
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
-
-
- }
-
-
- }
- }
Output chamber
In Gmail:
Hope you liked it. Have a good day. Thank you for reading.