2011-09-26 9 views
13

Questo è il mio web.config:C# - Non è possibile inviare la posta in Windows Azure tramite Gmail SMTP

<system.net> 
    <mailSettings> 
     <smtp deliveryMethod="Network"> 
      <network defaultCredentials="true" enableSsl="true" host="smtp.gmail.com" port="25" userName="[email protected]" password="xxxxxxxxxxx"/> 
     </smtp> 
    </mailSettings> 
</system.net> 

mio metodo:

public static void EmailVerification(string email, string nickname) 
    { 
     MailAddress from = new MailAddress("xxxxxxxxxxx", "xxxxxxxxxxxx"); 
     MailAddress to = new MailAddress(email); 

     MailMessage message = new MailMessage(from, to); 

     message.Subject = "Test"; 
     message.Body = "Test"; 
     SmtpClient client = new SmtpClient(); 

     try 
     { 
      client.Send(message); 
     } 
     catch(SmtpFailedRecipientException ex) 
     { 
      HttpContext.Current.Response.Write(ex.Message); 
      return; 
     } 
    } 

mio fallimento SmtpException:

Failure sending mail. 

InnerException:

Unable to connect to the remote server 

Lo sto testando localmente ma immagino che dovrebbe funzionare. Devo eseguirlo su Windows Azure, ho provato e non ha funzionato troppo. C'è qualcosa che mi manca?

+0

Vedere questa domanda: http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail/32336#32336 –

risposta

7

Le opzioni di autenticazione di base e le credenziali di rete predefinite si escludono a vicenda; se si imposta defaultCredentials su true e si specifica un nome utente e una password, viene utilizzata la credenziale di rete predefinita e i dati di autenticazione di base vengono ignorati.

Usa

<system.net> 
    <mailSettings> 
     <smtp deliveryMethod="Network"> 
      <network enableSsl="true" host="smtp.gmail.com" port="25" userName="[email protected]" password="xxxxxxxxxxx"/> 
     </smtp> 
    </mailSettings> 
</system.net> 
+0

vedo, ho usato come questo : Avevo bisogno di cambiare la porta in 587 –

Problemi correlati