Is it possible to send email from my computer(localhost) using asp.net project in C#? Finally I am going to upload my project into webserver but I want to test it before upl
Send Email with Attachment using asp.net C#
public void Send(string from, string to, string Message, string subject, string host, int port, string password)
{
MailMessage email = new MailMessage();
email.From = new MailAddress(from);
email.Subject = subject;
email.Body = Message;
SmtpClient smtp = new SmtpClient(host, port);
smtp.UseDefaultCredentials = false;
NetworkCredential nc = new NetworkCredential(txtFrom.Text.Trim(), password);
smtp.Credentials = nc;
smtp.EnableSsl = true;
email.IsBodyHtml = true;
email.To.Add(to);
string fileName = "";
if (FileUpload1.PostedFile != null)
{
HttpPostedFile attchment = FileUpload1.PostedFile;
int FileLength = attchment.ContentLength;
if (FileLength > 0)
{
fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Path.Combine(Server.MapPath("~/EmailAttachment"), fileName));
Attachment attachment = new Attachment(Path.Combine(Server.MapPath("~/EmailAttachment"), fileName));
email.Attachments.Add(attachment);
}
}
smtp.Send(email);
}
for complete tutorial step by step (with Video) visit http://dotnetawesome.blogspot.in/2013/09/send-email-with-attachment-using-cnet.html