I am learning .net and I am trying to write code for email sending in the asp.net but I am not able to write. Any help would be highly appreciated
I am learning .net and I am trying to write code for email sending in the asp.net but I am not able to write. Any help would be highly appreciated
Try the following code which is resolve your problem.
using System.Net;
using System.Net.Mail;
{
//MailMessage mailMessage = new MailMessage(txtFrom.Text, txtTo.Text);
//mailMessage.Subject = txtSubject.Text;
//mailMessage.Body = txtBody.Text;
MailMessage mailMessage = new MailMessage (From, To)
mailMessage.Subject = "Resume";
mailMessage.Body = "Hi";
if (FileUpload1.HasFile)
try
{
mailMessage.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
}
catch (Exception ex)
{
lblSendMsg.Text = "ERROR: " + ex.Message.ToString();
}
else
{
//lblAttError.Text = "You have not specified a file.";
}
try
{
SmtpClient Smtp = new SmtpClient();
Smtp.Send(mailMessage);
lblSendMsg.Text = "Message Send Successfully";
}
catch (Exception ex)
{
lblSendMsg.Text = "ERROR: " + ex.Message.ToString();
}
}
Bookmarks