Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <appSettings>
- <add key="PFUserName" value="abc@gmail.com"/>
- <add key="PFPassWord" value="xxxxxxxxxxxxx"/>
- <add key="smtpClient" value="smtp.gmail.com"/>
- <add key="SmtpServerPort" value="587"/>
- </appSettings>
- </configuration>
- using System.Configuration;
- namespace SendingMessage.ControlTemplates.SendingMessage
- {
- public partial class SendingMessage : UserControl
- {
- protected void btn1_Click(object sender, EventArgs e)
- {
- string userName = ConfigurationManager.AppSettings["PFUserName"];
- string password = ConfigurationManager.AppSettings["PFPassWord"];
- string smtpClient = ConfigurationManager.AppSettings["smtpClient"];
- string smtpPort = ConfigurationManager.AppSettings["SmtpServerPort"];
- try
- {
- MailMessage mail = new MailMessage();
- SmtpClient SmtpServer = new SmtpClient(smtpClient);
- mail.From = new MailAddress("xyz@gmail.com");
- mail.To.Add(lbl_mailId.Text.Trim());
- mail.Subject = "Test Mail";
- mail.Body = txt_mail.Text.Trim();
- SmtpServer.Port = int.Parse(smtpPort);
- SmtpServer.Credentials = new System.Net.NetworkCredential(userName, password);
- SmtpServer.EnableSsl = true;
- SmtpServer.Send(mail);
- txt_mail.Text = "";
- }
- catch (Exception ex)
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement