How to send email automatically using windows application?
In this article i have explained about how to send email automatically using windows application and windows scheduler. The Windows scheduler automatically executes your .exe file and sends mail to customer without any manual operation. Once we mention day & time then automatically email send every mention time until you stop that scheduler operation.
Description:
Automatic email sending process is easy to using windows scheduler and use of .exe file for send email automatically. For example every day you like send email automatically for tell Good Morning! message to your friend then refer below process.
Select File->New Project->windows form application in Visual Studio.
Form Design:
No control is used in the form design
Server side:
Double click on the form form_load event is occurred you can write where ever you want process execution code. I created mail code for send automatically mail send.
using System.Net;
using System.Net.Mail;
private void Form1_Load(object sender, EventArgs e)
{
try
{
MailMessage msg = new MailMessage("fromid@gmail.com", "tomailid@anydomain.com", "subjectofmail", "Mail_Body like Good Morning etc.");
SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);
NetworkCredential NetCrd = new NetworkCredential("fromid@gmail.com", "fromidpassword");
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = NetCrd;
mailClient.EnableSsl = true;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.Send(msg);
}
catch (Exception ex)
{
}
}
How to create .exe file for my windows application?
You no need to create any .exe file after write code just build application and run application, test the application for whether you got mail or not. Then automatically .exe file is created in the source location bin->Debug folder.
How to add .exe file into windows Scheduler?
Select Control panel->Scheduled Tasks->Double click of add scheduled task
New small window is opened click next browse your .exe location (.exe in your project location bin->Debug) and add it further next click allot schedule time and which day that .exe execute (daily/monthly/weekly etc). After select all options click finish. Then whenever your scheduled time are come that .exe file run automatically and send mail to customer.
Conclusion:
We learn in this article how to send email using windows scheduler at the specified mention time. I hope this article is help to you.