using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
using System.Net;
using System.Drawing;
using System.IO;
public partial class Feedback : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void EmailFeedback()
{
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress(txtEmail.Text.Trim());
mail.To.Add("anwar@csharpexample.com");
//set the content
mail.Subject = "Enquiry Form";
//Body to be displayed
mail.Body = "<h2>" + "Enquiry from " + " " + txtName.Text + "</h2>" + "<br><br>" +
"Subject: " + txtSubject.Text + "<br>" +
"Email : " + txtEmail.Text.Trim() + "<br>" +
"InQuiry: " + txtInquiry.Text.Trim() + "<br>" +
"Thank You";
//Attachment
if (fldAttchment.HasFile)
{
string fileName = Path.GetFileName(fldAttchment.PostedFile.FileName);
Attachment myAttachment =
new Attachment(fldAttchment.FileContent, fileName);
mail.Attachments.Add(myAttachment);
}
mail.IsBodyHtml = true;
// smtp settings
SmtpClient smtp = new SmtpClient("mail.csharpexample.com");
NetworkCredential SMTPUserInfo = new NetworkCredential("anwar@csharpexample.com", "Abcd123adsf@");
smtp.Credentials = SMTPUserInfo;
smtp.Send(mail);
}
private void Clear()
{
txtName.Text = string.Empty;
txtSubject.Text = string.Empty;
txtEmail.Text = string.Empty;
txtInquiry.Text = string.Empty;
}
protected void btnSubmit_Click1(object sender, EventArgs e)
{
EmailFeedback();
lblMsg.ForeColor = Color.Green;
Clear();
lblMsg.Text = "Thank You for Your Inquiry";
}
}