2009-09-01 18 views
6

Ho un'applicazione ASP.NET ospitata su Godaddy da cui voglio inviare email. Quando viene eseguito, ottengo: Nome cassetta postale non consentito. La risposta del server era: mi dispiace, inoltro negato dalla tua posizione. Le parti importanti del codice e web.config sono al di sotto:Impossibile inviare e-mail in ASP.NET tramite i server Godaddy

msg = new MailMessage("[email protected]", email); 
     msg.Subject = "GreekTools Registration"; 
     msg.Body = 
      "You have been invited by your organization to register for the GreekTools recruitment application.<br/><br/>" + 
      url + "<br/><br/>" + 
      "Sincerely,<br/>" + 
      "The GreekTools Team"; 

     msg.IsBodyHtml = true; 

     client = new SmtpClient(); 
     client.Host = "relay-hosting.secureserver.net"; 

     client.Send(msg); 

<system.net> 
<mailSettings> 
    <smtp from="[email protected]"> 
    <network host="relay-hosting.secureserver.net" port="25" userName="********" password="*********" /> 
    </smtp> 
</mailSettings> 

risposta

17

1- Se il sito è ospitato su Godaddy, è possibile utilizzare "relay-hosting.secureserver.net" senza credenziali.

2- Se il sito è ospitato al di fuori di godaddy, è possibile utilizzare "smtpout.secureserver.net" con le credenziali dell'account e-mail.

PS: Si prega di modificare la porta 3535, se avete problemi con il 25

Hosted su GoDaddy

<system.net> 
     <mailSettings> 
     <smtp from="[email protected]"> 
     <network host="relay-hosting.secureserver.net"/> 
     </smtp> 
     </mailSettings> 
    </system.net> 

esterno

<system.net> 
    <mailSettings> 
     <smtp from="[email protected]"> 
     <network host="smtpout.secureserver.net" 
      userName="[email protected]" password="your_password_here" 
      port="25" /> 
     </smtp> 
    </mailSettings> 
    </system.net> 
+0

Stavo riscontrando problemi con l'utilizzo di 'relay-hosting.secureserver.net' come' smtpClient.Host'. A volte ci è voluto molto tempo per l'invio, mentre altri inviano un'eccezione: "Nome della casella di posta non consentito. La risposta del server è stata: mi dispiace, inoltro negato dalla tua posizione". Cambiare il mio host in 'smptout.secureserver.net' ha risolto questo problema e consente di spedire la posta in pochi secondi. Grazie mille: D +1 –

+0

Godaddy ha apportato alcune modifiche con la loro infrastruttura di posta elettronica. Puoi creare il tuo account e-mail in diversi data center. quindi puoi scegliere i server America, Europa o Asia. Per questo motivo è necessario utilizzare un server smtp per la tua regione. come "smtpout.europe.secureserver.net" –

+0

Il mio problema era il porto 25. Grazie mille per aver suggerito la porta 3535. Ha funzionato come un fascino! – curiousBoy

0

Questo è probabilmente una risposta dal server SMTP perché la macchina si tenta di inviare e-mail non è stato whitelist (o è nella lista nera per SPAM). Relay-hosting.secureserver.net è un server GoDaddy o si trova su una rete diversa? Potresti voler trovare un server GoDaddy che consente di inoltrare la posta elettronica. Immagino che oggi molti provider di hosting condiviso abbiano restrizioni.

Vorrei sapere che tipo di server SMTP si sta utilizzando e quali misure antispam sono in atto. L'amministratore potrebbe essere in grado di aggiungere il server GoDaddy alla whitelist degli host consentiti. Devi stare molto attento e assicurarti che l'applicazione non possa essere utilizzata come proxy per uno spammer. Assicurati di convalidare tutti gli input per assicurarti che sia sicuro.

+0

relay-hosting.secureserver.net è il server di inoltro smtp di GoDaddy. – Jared

0

Controlla il tuo nome host. Sei sicuro il tuo account non è configurato per utilizzare mail.greektools.net? Questo è il formato predefinito per GoDaddy web hosting ..

+0

Ho provato a cambiarlo in mail.greektools.net e ho ricevuto un'eccezione generica di "mancato invio" (o qualcosa del genere). – Jared

0

set

defaultCredentials="false" 

nel vostro elemento di rete

 <network host="relay-hosting.secureserver.net" port="25" userName="********" password="*********" defaultCredentials="false" /> 
0

Proprio per un test. Rimuovere i valori di nome utente e password da web.config.

Poi, nel codice impostato

//call this line, before you call .Send 
client.Credentials = CredentialCache.DefaultNetworkCredentials; 
client.Send(msg) 
0

ho solo chiesto GoDaddy, come impostare un modulo SMTP mailer, e mi hanno detto che avevo bisogno di utilizzare un server di inoltro, senza nome utente, nessuna password e nessuna porta. Il nome del server da usare era lo stesso nome che hai usato.

2

Ecco la mia classe e-mail:

public class Email 
{ 
    public enum MailAddressType 
    { 
     From = 1, 
     Bcc 
    } 

    private static MailAddress _from = null; 

    public static void SendEmail(string to, string subject, string body) 
    { 
     SendEmail(to, subject, body, From, string.Empty); 
    } 

    public static void SendEmail(string to, string subject, string body, string from) 
    { 
     SendEmail(to, subject, body, from, MailAddressType.From); 
    } 

    public static void SendEmail(string to, string subject, string body, string addresses, MailAddressType addressType) 
    { 
     MailAddress from = From; 
     string bcc = string.Empty; 

     if (MailAddressType.From == addressType) 
     { 
      from = new MailAddress(addresses); 
     } 
     else 
     { 
      bcc = addresses; 
     } 

     SendEmail(to, subject, body, from, bcc); 
    } 

    private static void SendEmail(string to, string subject, string body, MailAddress from, string bcc) 
    { 
     MailMessage message = new MailMessage(); 
     message.From = From; 
     message.To.Add(to); 
     if (!string.IsNullOrEmpty(bcc)) 
     { 
      message.Bcc.Add(bcc); 
     } 
     message.ReplyTo = from; 
     message.Subject = subject; 
     message.Body = HttpContext.Current.Server.HtmlEncode(body); 
     SmtpClient smtp = new SmtpClient(); 
     smtp.Send(message); 
    } 

    public static MailAddress From 
    { 
     get 
     { 
      if (null == _from) 
      { 
       SmtpSection section = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); 
       string address = section.From; 
       string displayName = ConfigurationManager.AppSettings["fromEmailDisplayName"]; 
       _from = new MailAddress(address, displayName); 
      } 
      return _from; 
     } 
    } 
} 

E qui ci sono le relative impostazioni web.config:

<appSettings> 
    <add key="fromEmailDisplayName" value="Firstname Lastname"/> 
</appSettings> 

<system.net> 
    <mailSettings> 
     <smtp deliveryMethod="Network" from="[email protected]"> 
      <network host="relay-hosting.secureserver.net" /> 
     </smtp> 
    </mailSettings> 
</system.net> 

Per me, la chiave era "message.From = Da" del messaggio e ". ReplyTo = da ". GoDaddy sembra voler che il messaggio provenga da un indirizzo nel tuo dominio. Pertanto, per le pagine di contatto, utilizzare l'indirizzo e-mail predefinito come Da e impostare il mittente come ReplyTo. L'e-mail passa bene dopo.

0
var message = new MailMessage(); 
message.To.Add(new MailAddress("email-address")); 
message.From = new MailAddress("email-address"); 
message.Subject = "subject"; 
message.Body = string.Format("message-body"); 
message.IsBodyHtml = true; 
using (var smtp = new SmtpClient()) 
{ 
    smtp.Host = "relay-hosting.secureserver.net"; 
    smtp.EnableSsl = false; 
    smtp.Credentials = CredentialCache.DefaultNetworkCredentials; 
    await smtp.SendMailAsync(message); 
} 
0

Per coloro che vogliono sapere quello che dovrebbe essere Il codice C# oltre alla risposta accettata, sotto il codice ha funzionato per me. Si noti che l'indirizzo "from" è già citato in web.config nella risposta accettata, quindi non è necessario menzionarlo nel codice C#.

public static void SendMail(string emailid, string subject, string body) 
    { 
     System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); 

     System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); 

     msg.To.Add(new MailAddress(emailid)); 

     msg.Subject = subject; 
     msg.IsBodyHtml = true; 
     msg.Body = body; 

     client.Send(msg); 
    } 
Problemi correlati