Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using .Net3.5 with C#,

This is my code

C#
protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string mailto = "xxxxxxx@gmail.com";
                MailMessage messagemail = new MailMessage();
                MailMessage mymessage = new MailMessage();
                mymessage.From = new MailAddress("yyyyyy@gmail.com");
                mymessage.To.Add(mailto);
                mymessage.IsBodyHtml = true;
                mymessage.Subject = "Queries";
                mymessage.Body = "Name:" + TxtName.Text + "\nEmail Id:" + TxtEmailId.Text + "\nAddress:" + TxtAdress.Text + "\nMobile No.:" + TxtMobile.Text + "\nQueries/Feedback:" + TxtQueries.Text + "";
                SmtpClient sc = new SmtpClient();
                System.Net.NetworkCredential mycred = new System.Net.NetworkCredential("yyyyyy@gmail.com", "********");
                sc.Host = "Smtp.gmail.com";
                sc.Port = 587;
                sc.EnableSsl = true;
                sc.UseDefaultCredentials = false;
                sc.ServicePoint.MaxIdleTime = 1;
                sc.Credentials = mycred;
                sc.Send(mymessage);
                mymessage.Dispose();
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "javascript:alert('Thanks For Contacting Us. We Will Get Back To You Soon')", true);
                TxtName.Text = "";
                TxtAdress.Text = "";
                TxtEmailId.Text = "";
                TxtMobile.Text = "";
                TxtQueries.Text = "";
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "aa", "javascript:alert('"+ ex.Message +"')", true);
            }
        }

Its running Fine on local machine, but when I upload my web page it gives the following error

"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."

Although i used
sc.EnableSsl = true;

Please Help
Thanks
Faiz

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 20-Jul-12 21:03pm
v2

1 solution

Add this following in your web.config. Hope it works.
<trust level="Full" originUrl="www.gmail.com" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900