asp.net email send with attached document
//----------- send email to client with atteched document or fileuploader
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;
using System.Net.Mail;
//----------- send email to client with atteched document or fileuploader
protected void btnSubmit_Click(object sender, EventArgs e)
{
Label1.Text = "";
SmtpClient smtpClient = new SmtpClient();
// MailMessage message = new MailMessage();
try
{
NetworkCredential loginInfo = new NetworkCredential("pfcagra@gmail.com", "default123");
MailMessage msg = new MailMessage();
msg.From = new MailAddress(txtEmailid.Text.ToString());
msg.To.Add(new MailAddress("prince_footwear@yahoo.com"));
msg.CC.Add(new MailAddress("goyalpfc@yahoo.com"));
msg.Bcc.Add(new MailAddress("mhshry@gmail.com"));
string str = FileUpload2.FileName.ToString();
if (FileUpload2.HasFile)
{
msg.Attachments.Add(new Attachment(FileUpload2.PostedFile.InputStream, FileUpload2.FileName.ToString()));
}
msg.Subject = "Job Apply for -" + txtPosition.Text.ToString();
string msgBody = "Name -" + txtFullName.Text + "<br/> Position Apply for -" + txtPosition.Text + "<br/> Gender -" + CheckGender() + "<br/> Date of birth " + txtDOB.Text.ToString() + "<br/> <hr>Qualification -" + txtQualification.Text + "<br/> Professioanl Qualification -" + txtproQualification.Text + " <br/> Skills -" + txtSkills.Text.ToString() + "<br/> Exp." + DropDownList1.SelectedItem.Text + " " + DropDownList2.SelectedItem.Text + "<br/> Email id -" + txtEmailid.Text.ToString() + "<br/> contact No -" + txtContactNo.Text.ToString();
msg.Body = msgBody;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);
//MailAddress fromAddress = new MailAddress(txtEmailid.Text);
//smtpClient.Host = "localhost";
//smtpClient.Port = 25;
//message.From = fromAddress;
//message.To.Add("prince_footwear@yahoo.com");
//message.Bcc.Add("mhshry@gmail.com");
//message.IsBodyHtml = true;
//string str = FileUpload2.FileName.ToString();
//if (FileUpload2.HasFile)
//{
// message.Attachments.Add(new Attachment(FileUpload2.PostedFile.InputStream, FileUpload2.FileName.ToString()));
//}
//message.Subject ="Job Apply for -"+ txtPosition.Text.ToString();
//string msgBody = "Name -" + txtFullName.Text + "<br/> Position Apply for -" + txtPosition.Text + "<br/> Gender -" + CheckGender() + "<br/> Date of birth " + txtDOB.Text.ToString() + "<br/> <hr>Qualification -" + txtQualification.Text + "<br/> Professioanl Qualification -" + txtproQualification.Text + " <br/> Skills -" + txtSkills.Text.ToString() + "<br/> Exp." + DropDownList1.SelectedItem.Text + " " + DropDownList2.SelectedItem.Text + "<br/> Email id -"+txtEmailid.Text.ToString()+ "<br/> contact No -"+txtContactNo.Text.ToString() ;
//message.Body = msgBody;
//smtpClient.EnableSsl = true;
//smtpClient.Send(message);
Label1.Visible = true;
Label1.Text = "Your resume has been Sent, We Will Contact You Soon......";
Clertxt();
}
catch (Exception ex)
{
Label1.Text = "Send Email Failed." + ex.Message;
}
}
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;
using System.Net.Mail;
//----------- send email to client with atteched document or fileuploader
protected void btnSubmit_Click(object sender, EventArgs e)
{
Label1.Text = "";
SmtpClient smtpClient = new SmtpClient();
// MailMessage message = new MailMessage();
try
{
NetworkCredential loginInfo = new NetworkCredential("pfcagra@gmail.com", "default123");
MailMessage msg = new MailMessage();
msg.From = new MailAddress(txtEmailid.Text.ToString());
msg.To.Add(new MailAddress("prince_footwear@yahoo.com"));
msg.CC.Add(new MailAddress("goyalpfc@yahoo.com"));
msg.Bcc.Add(new MailAddress("mhshry@gmail.com"));
string str = FileUpload2.FileName.ToString();
if (FileUpload2.HasFile)
{
msg.Attachments.Add(new Attachment(FileUpload2.PostedFile.InputStream, FileUpload2.FileName.ToString()));
}
msg.Subject = "Job Apply for -" + txtPosition.Text.ToString();
string msgBody = "Name -" + txtFullName.Text + "<br/> Position Apply for -" + txtPosition.Text + "<br/> Gender -" + CheckGender() + "<br/> Date of birth " + txtDOB.Text.ToString() + "<br/> <hr>Qualification -" + txtQualification.Text + "<br/> Professioanl Qualification -" + txtproQualification.Text + " <br/> Skills -" + txtSkills.Text.ToString() + "<br/> Exp." + DropDownList1.SelectedItem.Text + " " + DropDownList2.SelectedItem.Text + "<br/> Email id -" + txtEmailid.Text.ToString() + "<br/> contact No -" + txtContactNo.Text.ToString();
msg.Body = msgBody;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);
//MailAddress fromAddress = new MailAddress(txtEmailid.Text);
//smtpClient.Host = "localhost";
//smtpClient.Port = 25;
//message.From = fromAddress;
//message.To.Add("prince_footwear@yahoo.com");
//message.Bcc.Add("mhshry@gmail.com");
//message.IsBodyHtml = true;
//string str = FileUpload2.FileName.ToString();
//if (FileUpload2.HasFile)
//{
// message.Attachments.Add(new Attachment(FileUpload2.PostedFile.InputStream, FileUpload2.FileName.ToString()));
//}
//message.Subject ="Job Apply for -"+ txtPosition.Text.ToString();
//string msgBody = "Name -" + txtFullName.Text + "<br/> Position Apply for -" + txtPosition.Text + "<br/> Gender -" + CheckGender() + "<br/> Date of birth " + txtDOB.Text.ToString() + "<br/> <hr>Qualification -" + txtQualification.Text + "<br/> Professioanl Qualification -" + txtproQualification.Text + " <br/> Skills -" + txtSkills.Text.ToString() + "<br/> Exp." + DropDownList1.SelectedItem.Text + " " + DropDownList2.SelectedItem.Text + "<br/> Email id -"+txtEmailid.Text.ToString()+ "<br/> contact No -"+txtContactNo.Text.ToString() ;
//message.Body = msgBody;
//smtpClient.EnableSsl = true;
//smtpClient.Send(message);
Label1.Visible = true;
Label1.Text = "Your resume has been Sent, We Will Contact You Soon......";
Clertxt();
}
catch (Exception ex)
{
Label1.Text = "Send Email Failed." + ex.Message;
}
}
thanks sir ......
ReplyDelete