Send email
i am developing a windows application, my database is in MS-Access. I have a form which stores the activation date and the expiry date of a product in the database. i want that when 5 days will be left for expiry of a product then application will automatically generate an email and send it to the administrator as a reminder and after that from that day it will keep on sending mail everyday till the expiry date i.e for 5 days cotinously. Please help me out
Posted Oct 27, 2009, 2:23 AM
Here is the program to send e-mail from an windows application.just change the mail contents as per your requirements...Any doubts feel free to ask..
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
namespace consolemail
{
class Program
{
static void Main(string[] args)
{
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
System.Net.NetworkCredential AuthInfo = new
System.Net.NetworkCredential("[email protected]", "babilona");
message.To.Add("[email protected]");
message.Subject = "Test Mail using System.Net.Mail";
message.From = new MailAddress("[email protected]");
string str = "Hai to all";
message.Body = str;
bool isBodyHtml = true;
message.IsBodyHtml = isBodyHtml;
message.Attachments.Add(new Attachment("c:\\something.txt"));
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Priority = MailPriority.High;
smtp.Host = "smtp.gmail.com";
smtp.UseDefaultCredentials = false;
smtp.Credentials = AuthInfo;
smtp.Timeout = 20000;
smtp.Port = 587;
// use stmp.port = 587 if 465 does not work.
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
smtp.Send(message);
Console.WriteLine("E-mail has been sent succesfully");
Console.ReadLine();
}
catch (System.Net.Mail.SmtpException ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
}
Don't forget to mark it as a correct answer if it helped u............
naura paxPosted Oct 27, 2009, 1:43 AM
Create a windows service application and schedule it to run on server daily.
In this application you can access your database and send mail using smtp mail client.