System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'mailrelay'
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback)
at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at EmailSender.PerformDelivery(IMessage message)
below is my code
mail = new MailMessage();
string[] toAddresses = email.To.EmailAddress.Split(new char[] { ';' });
foreach (string toAddress in toAddresses)
{
if (!string.IsNullOrEmpty(toAddress.Trim()))
{
mail.To.Add(new MailAddress(toAddress));
}
}
string[] ccAddresses = email.CcEmail.Split(new char[] { ';' });
foreach (string ccAddress in ccAddresses)
{
if (!string.IsNullOrEmpty(ccAddress.Trim()))
{
mail.CC.Add(new MailAddress(ccAddress));
}
}
string[] bccAddresses = email.BccEmail.Split(new char[] { ';' });
foreach (string bccAddress in bccAddresses)
{
if (!string.IsNullOrEmpty(bccAddress.Trim()))
{
mail.Bcc.Add(new MailAddress(bccAddress));
}
}
mail.From = new MailAddress(email.From.EmailAddress,email.From.FullName);
mail.Subject = email.Subject;
mail.Body = email.Body;
if (email.Body.Contains("<html>"))
{
mail.IsBodyHtml = true;
}
if (!email.ExcludeAttachment && !string.IsNullOrEmpty(email.AttachmentPath))
mail.Attachments.Add(new Attachment(email.AttachmentPath));
client = new SmtpClient();
client.Host = ConfigurationSettings.AppSettings["SmtpServer"].ToString();
client.Send(mail);
Aucun commentaire:
Enregistrer un commentaire