I get this ‘pop-up’ error when I press the send button in debug mode to a specific address from the ‘txtMail'(receiver):
MailerException was unhandled by user code
Mailbox unavailable.
The
server response was: 4.7.1 Client host rejected: cannot find your
hostname, [IP]
The code actually trips over the last line, which is:
catch(Exception ex)
{
throw new MailerException(ex.Message, ex);
}
I don’t think there is a problem with the code itself, but here is the whole code so maybe someone can spot the issue:
public void SendMail()
{
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
// Mail from
if (!string.IsNullOrEmpty(this.mailFrom))
message.From = new MailAddress(this.mailFrom);
else
message.From = from;
if (!IsValidEmailAddress(message.From.Address))
throw new MailAddressException("From address " + message.From + " is not valid");
//message.From = from;
// Add recipients
if (_RecipientNames.Count == 0)
throw new RecipientException("No recipients added");
StringBuilder Recipients = new StringBuilder();
for(int i = 0; i < _RecipientEmailAddresses.Count; i++)
{
if (_RecipientNames[i].ToString().Length > 0)
message.To.Add(new MailAddress((string)_RecipientEmailAddresses[i], (string)_RecipientNames[i]));
else
message.To.Add(new MailAddress((string)_RecipientEmailAddresses[i]));
}
foreach (MailAddress ma in this._Bcc)
message.Bcc.Add(ma);
if (this._ReplyToAddress != null)
message.ReplyTo = this._ReplyToAddress;
message.Subject = _Subject;
message.IsBodyHtml = this.isHtmlMail;
message.BodyEncoding = this.BodyEncoding;
// Priority
message.Priority = this.priorityLevel;
// Load template file?
if (_TemplateFile.Length > 0)
{
message.Body = GetMailTemplateContents();
}
else
message.Body = _MailBody;
// Attachments given?
if (this.attachments.Count > 0)
{
foreach (Attachment a in this.attachments)
message.Attachments.Add(a);
}
SmtpClient client = new SmtpClient(_SmtpServer);
try
{
client.Send(message);
}
catch(System.Web.HttpException ex)
{
throw new MailerException(ex.Message,ex);
}
catch(System.Runtime.InteropServices.COMException ex)
{
// Rethrow the exception
throw new MailerException(ex.Message, ex);
}
catch(Exception ex)
{
throw new MailerException(ex.Message, ex);
}
Some may say that this is actually an error code returned by the server I’m attempting to deliver to. (Mailbox full, invalid e-mail address etc)
Either way, or does it needs to be resolved by the admin of the mail server?
is there anyone who might know why this error might occur?
Willing to provide any other/more information if needed.
Thanks in Advance,
This looks like the recieving SMTP server rejected the message. I am guessing it tried to do a reverse lookup on your IP and Hostname and was not able to find a match. This is a common anti-spam practice.