Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code to send mail (test code):

C#
                //sending mail
var message = new System.Net.Mail.MailMessage();
    message.From = new MailAddress("J2v@gmail.com");
    message.To.Add(model.Mailag);
    message.Subject = "Valdation d'inscription";
    message.Body = "Votre inscription a été valide voici vos cordonne de conexion ID user : "+model.Idag+" Password : "+user.password;
    var client = new  System.Net.Mail.SmtpClient
    {
        Host = "smtp.gmail.com",
        Port = 587,
        EnableSsl = true,
        UseDefaultCredentials = false,
        Credentials = new NetworkCredential("", "")
    };
client.Send(message);

When i try it i got this error : SMTP server require secured connexion or you are not connected. Server response was :5.5.1 Authentication Required. On this line client.Send(message);
Posted
Comments
Dr.Walt Fair, PE 6-Apr-12 18:13pm    
Well, it appears that perhaps your SMTP server isn't connecting because it requires a secure connection or it's not correctly authenticating.

So, what type of connection are you using and how is the authentication handled?
[no name] 6-Apr-12 22:02pm    
Hmmm..... I wonder what the problem could be...
UseDefaultCredentials = false,
Credentials = new NetworkCredential("", "")
Amrut Bidri 25-Apr-12 3:14am    
use the following two lines of code instead of the last line..

client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(message);

thanks

I think this mail setting should help you :
defaultCredentials="false"
XML
<system.net>
    <mailSettings>
      <smtp from="info@domain.com">
        <network defaultCredentials="false" host="mail.domain.com" port="587" userName="info@.domain.com" password="pass"/>
      </smtp>
    </mailSettings>
  </system.net>

And also check this:
https://github.com/smsohan/MvcMailer[^]
 
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