Hello Sir
I want To send email through windows services. i wrote the code but my email not send
Can Anyone help me
Thanks in advance
public void sendEmail()
{
string To = "ashhad.saud1992@gmail.com";
string From = "ashhad.saud1992@gmail.com";
string DisplayName = "Ashhad";
string Host = "localhost";
string Subject = "Patient Statement";
string Body = "Please find attached the Patient Statement report ";
MailMessage msg = new MailMessage();
if (!To.Contains(","))
{
msg.To.Add(To);
}
else
{
foreach (string strTo in To.Split(new char[] { ',' }))
{
msg.To.Add(strTo);
}
}
MailAddress fromAddress = new MailAddress(From, DisplayName);
msg.From = fromAddress;
SmtpClient smtp = new SmtpClient(Host);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
string InfoInMail = string.Empty;
//int ProcessSuccessCount = 0;
msg.IsBodyHtml = true;
msg.Subject = Subject;
msg.Body = Body;
Attachment attach = new Attachment("muxam_hmeghani_10172015_1523.pdf");
msg.Attachments.Add(attach);
smtp.Send(msg);
}
protected override void OnStart(string[] args)
{
sendEmail();
Library.writeErrorLog("Daily Reporting service started");
}
protected override void OnStop()
{
Library.writeErrorLog("Daily Reporting service stooped");
}