using System.Net.Mail;
using System.Text;
public string SendFromMail, SendToMail, Body, subject;
public void SendMail(string SendToMail, string SendFromMail, string subject, string Body)
{
try
{
MailAddress SendFrom = new MailAddress(SendFromMail);
MailAddress SendTo = new MailAddress(SendToMail);
MailMessage MyMessage = new MailMessage(SendFrom, SendTo);
MyMessage.Subject = subject;
MyMessage.Body = Body;
MyMessage.IsBodyHtml = true;
string mSMTPServer = "smtpout.secureserver.net";// ConfigurationSettings.AppSettings["smtpServer"].ToString();
SmtpClient SmtpMail = new SmtpClient(mSMTPServer);
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("hr@companyname.com ", "Password");//that mail where i send the mail
SmtpMail.UseDefaultCredentials = false;
SmtpMail.Credentials = SMTPUserInfo;
SmtpMail.Send(MyMessage);
}
catch (Exception ex)
{
ex.ToString();
}
}
void SendMailToUser()
{
SendFromMail = "hr@companyname.com";
SendToMail = "hr@companyname.com";
subject = "Enquiry";
Body += "Dear Support," + "<br /><br />There was an enquiry from companyname.com. Following are the details:";
Body += "<br /><br /> Name: " + txtfullname.Text;
Body += "<br />Email Id: " + txtemailAddress.Text;
Body += "<br />Mobile No: " + txtMobileno.Text;
Body += "<br />Address: " + txtAddress.Text;
Body += "<br />City: " + txtcity.Text;
Body += "<br />Message: " + txttotalexperience.Text;
Body += "<br /><br /><br />Regards";
Body += "<br />System Admin";
Body += "<br />companyname.com";
//Body += "Name: <br /><br />Please use the following key to register your app upon the first run of the application:<br /><br /><div align=\"center\">";
SendMail(SendFromMail, SendToMail, subject, Body);
}
void SetTheReplyToHeader()
{
StringBuilder builder = new StringBuilder();
builder.Append("Dear");
builder.Append(" ");
builder.Append(txtfullname.Text).AppendLine().AppendLine();
builder.Append("Thanks for your query. A HR executive will shortly contact you soon.").AppendLine().AppendLine();
builder.Append("Regards").AppendLine();
builder.Append("Support Team").AppendLine();
builder.Append("xxxxxxxxxxxxxx").AppendLine();
builder.Append("xxxxxxxxxxxxxx
builder.Append("xxxxxxxxxxx
builder.Append("xxxxxxxxxxxxxxxxx).AppendLine();
MailMessage mail = new MailMessage();
SmtpClient SmtpServers = new SmtpClient("smtpout.secureserver.net"); //Mail Server Name
mail.From = new MailAddress("hr@companyname.us");
mail.To.Add(txtemailAddress.Text);//Who save the data
mail.Subject = "companyname";
mail.Body += builder.ToString();
SmtpServers.Port = 25;
SmtpServers.UseDefaultCredentials = true;
SmtpServers.Credentials = new System.Net.NetworkCredential("hr@companyname.com ", "Password");
SmtpServers.Send(mail);
}
No comments:
Post a Comment