Advertisement
Guest User

Untitled

a guest
Dec 27th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.  
  4. <appSettings>
  5. <add key="PFUserName" value="abc@gmail.com"/>
  6. <add key="PFPassWord" value="xxxxxxxxxxxxx"/>
  7. <add key="smtpClient" value="smtp.gmail.com"/>
  8. <add key="SmtpServerPort" value="587"/>
  9. </appSettings>
  10. </configuration>
  11.  
  12. using System.Configuration;
  13. namespace SendingMessage.ControlTemplates.SendingMessage
  14. {
  15. public partial class SendingMessage : UserControl
  16. {
  17.  
  18. protected void btn1_Click(object sender, EventArgs e)
  19. {
  20. string userName = ConfigurationManager.AppSettings["PFUserName"];
  21. string password = ConfigurationManager.AppSettings["PFPassWord"];
  22. string smtpClient = ConfigurationManager.AppSettings["smtpClient"];
  23. string smtpPort = ConfigurationManager.AppSettings["SmtpServerPort"];
  24. try
  25. {
  26. MailMessage mail = new MailMessage();
  27. SmtpClient SmtpServer = new SmtpClient(smtpClient);
  28. mail.From = new MailAddress("xyz@gmail.com");
  29. mail.To.Add(lbl_mailId.Text.Trim());
  30. mail.Subject = "Test Mail";
  31. mail.Body = txt_mail.Text.Trim();
  32. SmtpServer.Port = int.Parse(smtpPort);
  33. SmtpServer.Credentials = new System.Net.NetworkCredential(userName, password);
  34. SmtpServer.EnableSsl = true;
  35. SmtpServer.Send(mail);
  36. txt_mail.Text = "";
  37. }
  38. catch (Exception ex)
  39. {
  40.  
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement