I cannot send email with this code, my label showed 'failure sending mail'. Pls help me. yemail = sender's email. Email = recepient's email. emailp = Sender's Password
using System.Net;
using System.Net.Mail;
protected void end_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(yemail.Text, "Sender's Name");
msg.To.Add(new MailAddress(Email.Text));
msg.Subject = Subject.Text;
msg.Body = Message.Text;
msg.IsBodyHtml = true;
if(FileUpload1.HasFile)
{
msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
}
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Credentials = new NetworkCredential(yemail.Text, emailp.Text);
Label1.Visible = true;
try
{
smtp.Send(msg);
Label1.Text = "Email Send successfully";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}