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.
fonte
2010-03-21 21:41:41
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 –
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" –
Il mio problema era il porto 25. Grazie mille per aver suggerito la porta 3535. Ha funzionato come un fascino! – curiousBoy