Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My site has some functionality to send email to user some perspective. I have done this. My method can sending email successfully when i am running this application from Visual Studio or My local IIS 7 server (I Configured My PC). But the remote online web server can't send email. Please give me some tips how can i solve this issue. I have already gave lot of time to google but not found this solution. My code

const string fromAddress = "ejobsbdinfo@gmail.com";
const string fromPassword = "password";
string toAddress = account.Email;
string subject = "subject";
string body = "mail Body";
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
smtp.Send(fromAddress, toAddress, subject, body);

give me some instruction how can i solve this problem.
Posted
Comments
Bernhard Hiller 28-Mar-13 4:11am    
what's the error message?
Member 9399759 28-Mar-13 4:32am    
Thanks for reply , The exception is bellow....

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

C#
using System.Net;
using System.Net.Mail;

C#
public partial class RegistrationForm : System.Web.UI.Page
   {
    
       protected void Page_Load(object sender, EventArgs e)
       {

       }


C#
protected void send mail(object sender, EventArgs e)
     {

NetworkCredential cred = new NetworkCredential(email Id, Password);
            MailMessage msg = new MailMessage();
            msg.To.Add(TextBox4.Text);
            msg.Subject = "Welcome To Website";
           
            msg.Body = "You Have Successfully Registered" ;
            msg.From = new MailAddress("welcome@gmail.com"); // Your Email Id
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            SmtpClient client1 = new SmtpClient("smtp.mail.yahoo.com", 465);
            client.Credentials = cred;
            client.EnableSsl = true;
            client.Send(msg);

}

}
 
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