How to send mail in c#?

Posted by Tushar under C# on 2/22/2009 | Views : 1517 | Status : [Member] | Replies : 2
i was sending mail to my personal software to any user personal mail id .




Responses

Posted by: Vuyiswamb on: 2/24/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day Tushar

English is neither my mother tongue, but i think we as programmers should work very hard to understand and write it. What you have written here does not make sense at all. Please before you post make sure that the other person reading your message will understand it. Please rephrase your question

Thank you

Thank you for posting at Dotnetfunda
[Administrator]

Tushar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Athiraappukuttan on: 5/6/2009 [Member] Starter

Up
0
Down
private void SendMail()
{
try
{
MailMessage m_newmail = new MailMessage();
SmtpClient s_client = new SmtpClient();
string attachfile=string.Empty;
Attachment m_attach;
string attachfile1=string.Empty;
string strdir = string.Empty;
MailAddress fromAdr = new MailAddress(txtEmail.Text);
m_newmail.From = fromAdr;

string strMailId = System.Configuration.ConfigurationManager.AppSettings["MailId"].ToString();
m_newmail.To.Add(strMailId);
m_newmail.Subject = "About Enquiry";

StringBuilder MailBody = new StringBuilder();
MailBody.Append("Name :" + txtName.Text.Trim() + "<br/>");
MailBody.Append("Designation :" + txtDesgntn.Text + "<br/>");
MailBody.Append("Company Name :" + txtCoName.Text + "<br/>");
MailBody.Append("Address :" + txtAddress.Text + "<br/>");
MailBody.Append("Pin :" + txtPin.Text + "<br/>");
MailBody.Append("Country :" + txtCountry.Text + "<br/>");
MailBody.Append("Telephone :" + txtTel1.Text + "-" + txtTel2.Text + "-" + txtTel3.Text + "<br/>");
MailBody.Append("Fax :" + txtFax.Text + "<br/>");
MailBody.Append("Like to comment on :" + cmbComment.SelectedValue + "<br/>");
MailBody.Append("Suggestions :" + txtSuggestions.Text + "<br/>");
MailBody.Append("Please tell us what you are looking for in enquiry :" + chklstEnquiry.SelectedValue + "<br/>");
MailBody.Append("Additional Information :" + txtAdditionalInfo.Text + "<br/>");
MailBody.Append("How did you here about us :" + cmbSelect.SelectedValue + " <br/>");

m_newmail.Body = MailBody.ToString();
m_newmail.IsBodyHtml = true;

if(fileName.HasFile)
{
attachfile = Path.GetFileName(fileName.PostedFile.FileName);
fileName.PostedFile.SaveAs(Server.MapPath(attachfile));

m_attach = new Attachment(Server.MapPath(attachfile));

m_newmail.Attachments.Add(m_attach);
attachfile1 = attachfile;
}
s_client.Host = "localhost";
s_client.UseDefaultCredentials = true;
s_client.Send(m_newmail);

ClientScript.RegisterClientScriptBlock(this.GetType(), "Hi!", String.Format("alert('An email has successfully been sent to {0}');", m_newmail.To), true);
ClearAll();

m_newmail.Dispose();

if (attachfile1 != null)
{
File.Delete(Server.MapPath(attachfile1));
}
}
catch (Exception ex)
{
ClearAll();
}
}


Tushar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response