Click here to Skip to main content
15,891,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my asp page shows approval form for users. If i click accept means generate "user_id" and "Password". Then i want to send user_id and password via email. so i write this below code for sending email.
C#
private void send_mail()
    {
        MailMessage mail = new MailMessage();
        mail.To.Add(hdn_patemail.Value);
        mail.From = new MailAddress("abc@gmail.com");
        mail.Subject = "Your account details";
        //mail.Body = Label2.Text + lblreq.Text + lblpwd.Text + lblun.Text;
        mail.Body = "<html><head></head><body><table><tr><td>Dear friend,</td></tr></table></body></html>" + Session["PatName"].ToString() + "<br/>" + hdn_pwdd.Value + "<br/><html><body><table><tr><td>Regards,</td></tr><tr><td>Team-InfyMED</td></tr></table></body><html>";
        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "19.168.1.100";
        smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "abc@123");
        //smtp.EnableSsl = true;
        smtp.Send(mail);
    }


But i get error message "Mail sending failure "


Please some one help me
Posted

Try out this code:
C#
var smtp = new System.Net.Mail.SmtpClient();
   {
       smtp.Host = "smtp.gmail.com";
       smtp.Port = 587;
       smtp.EnableSsl = true;
       smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
       smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
       smtp.Timeout = 20000;
   }
   // Passing values to smtp object
   smtp.Send(fromAddress, toAddress, subject, body);
 
Share this answer
 
MailMessage mail = new MailMessage();
mail.To.Add(hdn_patemail.Value);
mail.From = new MailAddress("abc@gmail.com");
mail.Subject = "Your account details";
//mail.Body = Label2.Text + lblreq.Text + lblpwd.Text + lblun.Text;
mail.Body = "<html><head></head><body><table><tr><td>Dear friend,</td></tr></table></body></html>" + Session["PatName"].ToString() + "<br/>" + hdn_pwdd.Value + "<br/><html><body><table><tr><td>Regards,</td></tr><tr><td>Team-InfyMED</td></tr></table></body><html>";
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "abc@123");
smtp.EnableSsl = true;
smtp.Send(mail);


use smtp.gmail.com instead 19.168.1.100 and uncomment ssl statement.
 
Share this answer
 

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