Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...

how to send automatic mails daily from my website


thanks in advance..
Posted

You can create windows service, which will run on server once in 24 hours, which will send email depends on your business logic.

You can create it by using following link, which describes step by step guide,
http://msdn.microsoft.com/en-us/library/zt39148a.aspx[^]
 
Share this answer
 
v2
Comments
07405 7-Jul-12 2:32am    
i have to write code such that when user selects future date and button clicked mail should be received on that date just like e-cards.
Mukund Thakker 7-Jul-12 2:36am    
If you needs to send future email, than store the information and date in database and check every day. if both date match than send email to recipient.
07405 7-Jul-12 2:42am    
i am storing future date in database but how can i send on that particular date. i should not check daily it should sent automatically
Mukund Thakker 7-Jul-12 3:10am    
If you are storing future date, than in windows service you can check like
select * from table where future_date=getdate
and send email to all the recipient.

If still you have confusion, share your code snippet.I will provide you full solution.
07405 7-Jul-12 3:24am    
my query
Select * from Details where GETDATE()=DOB



protected void Button1_Click(object sender, EventArgs e)
{
cn.Open();
cm.Connection = cn;
cm.Parameters.Clear();

cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "getbirthdaydate";
SqlDataAdapter da = new SqlDataAdapter(cm);
da.Fill(ds);

foreach (System.Data.DataRow row in ds.Tables[0].Rows)
{

MailMessage msg = new MailMessage();
msg.From = new MailAddress("username");
msg.To.Add(ds.Tables[0].Rows[i]["Email"].ToString());
//msg.Bcc.Add(new MailAddress("bcc address"));
//msg.CC.Add(new MailAddress("cc address"));

msg.Subject = "subject of mail";
msg.Body = "message you want to send with email";
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;

smtp.Credentials = new NetworkCredential("username", "password");

cn.Close();
smtp.Send(msg);
i++;
}
}


this is my code for normal mail sending.
but i have send that mail on tomorrow means how can i store this mail and send it on tomorrow. if i write services does it possible?

thank u for ur continuous reply..
you can call this function as per your requirement

function:-
C#
public bool sandMail(string strTo, string strfrom,string password,string strSubject, string strBody)


{ MailMessage mailObj=new MailMessage();
SmtpClient clientObj = new SmtpClient();
clientObj.Credentials = new System.Net.NetworkCredential(strfrom, password);
clientObj.Host = "smtp.gmail.com";
clientObj.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
clientObj.EnableSsl = false;
clientObj.Port = 587;
MailAddress mailadTo = new MailAddress(strTo);
MailAddress mailfrom = new MailAddress(strfrom, "rizwan");
mailObj.To.Add(mailadTo);
mailObj.From = mailfrom;
mailObj.Subject = "hi";
mailObj.IsBodyHtml = true;
clientObj.Send(mailObj);
return true;
}
 
Share this answer
 
Comments
07405 7-Jul-12 2:36am    
can u explain me the purpose of clientObj.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
07405 7-Jul-12 2:36am    
i have to write code such that when user selects future date and button clicked mail should be received on that date just like e-cards.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900