- int cnt;
- try
- {
- mEmail = Session["mEmail"].ToString();
-
- MailMessage Msg = new MailMessage();
- Msg.From = new MailAddress(mEmail.Trim());
- Msg.To.Add("[email protected]");
- Msg.Bcc.Add("[email protected]");
- StreamReader reader = new StreamReader(Server.MapPath("~/SendMail.html"));
- string readFile = reader.ReadToEnd();
- string StrContent = "";
- StrContent = readFile;
-
- StrContent = StrContent.Replace("[MyName]", lblname.Text);
- string mSubject = "APPLICATION FOR ANNUAL LEAVE";
-
- StrContent = StrContent.Replace("[subject]", mSubject);
- StrContent = StrContent.Replace("[date1]", txtFromDate.Text.Trim());
- StrContent = StrContent.Replace("[date2]", txtToDate.Text.Trim());
- StrContent = StrContent.Replace("[ddays]",txtNODays.Text.Trim())+" days";
- Msg.Subject = mSubject + " FROM " + lblname.Text;
- Msg.Body = StrContent.ToString();
- Msg.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient();
- smtp.Host = "smtp.gmail.com";
- smtp.Port = 587;
- smtp.EnableSsl = true;
- smtp.Timeout = 40000;
- smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtp.UseDefaultCredentials = false;
- smtp.Credentials = new NetworkCredential("[email protected]", "Delladv!973@");
-
- smtp.Send(Msg);
-
- webMessage.Show("Mail sent successful.....");
- return cnt = 1;
- }
- catch (Exception ex)
- {
- webMessage.Show("Error : " + ex.Message.ToString());
- return cnt = -1;
- }
please i have tried all i know, i need your help, how to get smtp.gmail.com to work.
Thank you all