the smtp server requires a secure connection or the client was not authenticated.

Posted by Parthibansk under ASP.NET on 2/12/2013 | Points: 10 | Views : 1406 | Status : [Member] | Replies : 1
protected void sendemail()
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
//message.To.Add(new MailAddress("md.shadab.anwar@gmail.com"));
message.To.Add(new MailAddress(txtemail.Text.ToString()));
//string filename;
//filename = string.Concat(txtuploadfile.Text.Replace(@"\", @"\\"));
message.Subject = "New User Registration for " + txtuser.Text.ToString();
message.From = new System.Net.Mail.MailAddress("admin@XYZ.com");
//message.Body =
message.IsBodyHtml=true;




System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);

smtp.EnableSsl = true;

smtp.Send(message);
}




Responses

Posted by: aswinialuri-19361 on: 2/12/2013 [Member] Starter | Points: 25

Up
0
Down
Hii

better to use this if you have any doubt on this send me aquestion
you must add this two namespaces.
using System.Net.Mail;
using System.Net;
using System.Configuration;
public partial class ASPX_eMails : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
try
{
MailMessage msg = new MailMessage(txtfrommailid.Text,txttoemailid.Text,txtsubject.Text.ToString(),txtbody.Text.ToString());
msg.IsBodyHtml = true;
//if (FileUpload1.HasFile)
//{ // msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
//} if (FileUpload1.HasFile)
{ msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
} NetworkCredential Nc = new NetworkCredential(txtfrommailid.Text, "#######");
SmtpClient smtp = new SmtpClient("smtp.gmail.com",587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = Nc;
smtp.Send(msg);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Label1.Text = "Your mail is sent sucsessfull";
}}

Thanks& Regards
Aswini Aluri

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

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

Login to post response