Thanks a lot for giving solution,
now i use this code for sending mail,
protected void getDataforemail(int invitationID)
{
try
{
EventManagerDataContext db = new EventManagerDataContext();
{
var q = (from a in db.EMR_EVENTs
join b in db.EMR_CLIENTs on a.ClientID equals b.ClientID
join c in db.EMR_INVITATIONs on a.EventID equals c.EventID
where c.InvitationID == invitationID
select new
{
EventID = a.EventID,
Client_Name = b.Name,
Event_Name = a.Name,
Activation_Code = c.Activation_Code
});
var ev = q.FirstOrDefault();
StreamReader reader = new StreamReader(Server.MapPath("~/HTMLPage1.htm"));
string readFile = reader.ReadToEnd();
string myString = "";
myString = readFile;
MailAddress fromMail = new MailAddress("ketanitaliya16@gmail.com");
Msg.CC.Add(new MailAddress(clientEmail(getClientId(lblclientname.Text))));
myString = myString.Replace("$$Client_Name$$", ev.Client_Name);
myString = myString.Replace("$$Event_Name$$", ev.Event_Name);
myString = myString.Replace("$$Activation Code$$", ev.Activation_Code);
Msg.From = fromMail;
Msg.Subject = "Send Mail with HTML File";
Msg.Body = myString.ToString();
Msg.IsBodyHtml = true;
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromMail.ToString(), "xxxxxxxx");
smtp.Timeout = 20000;
}
smtp.Send(Msg);
reader.Dispose();
}
}
catch (Exception)
{
throw;
}
}
protected void getInvitationID(int EventID)
{
try
{
EventManagerDataContext db = new EventManagerDataContext();
{
var q = (from a in db.EMR_INVITATIONs
where a.EventID == EventID
select new
{
a.InvitationID
});
foreach (var inv in q)
{
var p = (from a in db.EMR_INVITATIONs
where a.InvitationID == inv.InvitationID
select new
{
a.Email_Address,
});
foreach (var emailadd in p)
{
Msg = new MailMessage();
Msg.To.Add(new MailAddress(emailadd.Email_Address));
getDataforemail(inv.InvitationID);
}
}
}
}
catch (Exception)
{
throw;
}
}
with using this code i can send mail from local server but when i uploaded it on server i can't send mail from server.
i got this error,
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
i find that mail is not send can anyone tell me solution for that.?