using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net.Security;
namespace SendEmail
{
public partial class SendEmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSentFeedBack_Click(object sender, EventArgs e)
{
MailMessage mailMsg =new MailMessage();
mailMsg.From = new MailAddress(txtEmail.Text);
mailMsg.IsBodyHtml = true;
mailMsg.Subject = "Contect Details";
mailMsg.Body = "Contact Detail" + "Name" + txtName.Text + "
Email-Email :" +
Email-Email :" +
txtEmail.Text + "
Comments :" + txtComment.Text;
Comments :" + txtComment.Text;
SmtpClient smtp = new SmtpClient("[email protected]", 587);
mailMsg.Priority = MailPriority.Normal;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]","abcd");
smtp.Timeout = 25000;
smtp.EnableSsl = true;
smtp.Send(mailMsg);
Label4.Text = "Thanks you.Your contect details and feed Back has been submited.";
}
}
}
Khan Abrar AhmedPosted Apr 15, 2014, 9:27 AM
static public void SendMail(System.Net.Mail.MailAddress fromAddress, string toAddress, string ccAddress,
string subject, string body)
{
string SmtpServer = ConfigSettings.GetProperty(Constants.SMTP_SERVER);
string SmtpUserName = ConfigSettings.GetProperty(Constants.SMTP_USERNAME);
string SmtpUserPass = ConfigSettings.GetProperty(Constants.SMTP_PASSWORD);
string smtpPort = ConfigSettings.GetProperty(Constants.SMTP_PORT);
System.Net.Mail.SmtpClient smtpSend = new System.Net.Mail.SmtpClient(SmtpServer);
using (System.Net.Mail.MailMessage emailMessage = new System.Net.Mail.MailMessage())
{
emailMessage.To.Add(toAddress);
if (!string.IsNullOrEmpty(ccAddress))
emailMessage.CC.Add(ccAddress);
emailMessage.From = fromAddress;
emailMessage.Subject = subject;
emailMessage.Body = body;
emailMessage.IsBodyHtml = true;
if (!Regex.IsMatch(emailMessage.Body, @"^([0-9a-z!@#\$\%\^&\*\(\)\-=_\+])", RegexOptions.IgnoreCase) ||
!Regex.IsMatch(emailMessage.Subject, @"^([0-9a-z!@#\$\%\^&\*\(\)\-=_\+])", RegexOptions.IgnoreCase))
{
emailMessage.BodyEncoding = Encoding.Unicode;
}
if (SmtpUserName != null && SmtpUserPass != null && smtpPort != null)
{
smtpSend.Port = Convert.ToInt32(smtpPort);
smtpSend.UseDefaultCredentials = false;
smtpSend.Credentials = new System.Net.NetworkCredential(SmtpUserName, SmtpUserPass);
}
try
{
smtpSend.Send(emailMessage);
}
catch (Exception ex)
{
AppException.HandleException(ex);
}
}
}
Istekhar AhmadPosted Apr 15, 2014, 4:29 AM