The server response was: 5.7.1 Unable to relay/Mailer Daemon - c#

I have gone through the answer to the below question and found it to be very helpful. However, I have a different question regarding the behavior of smtp servers.
Mailbox unavailable
and Relay configuration
Scenario:
I have two smtp servers which I do not have access to i.e. just the credentials. While sending email from 1 server I receive the below error:
Mailbox unavailable. The server response was: 5.7.1 Unable to relay
Type: System.Net.Mail.SmtpFailedRecipientException:
Source:System
Stack Trace: at System.Net.Mail.SmtpTransport.SendMail(MailAddress
sender, MailAddressCollection recipients, String deliveryNotify,
Boolean allowUnicode, SmtpFailedRecipientException& exception) at
System.Net.Mail.SmtpClient.Send(MailMessage message)
is very clear i.e. the smtp server was unable to relay the message. However, on other server the SendEmail method did not throw any exception but I received a Mailer Daemon Email message stating that :
This is the mail system at host test.relay.host.name.changed.
I'm sorry to have to inform you that your message could not be
delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You can delete your
own text from the attached returned message.
The mail system
test1.test2#hotmail.com: host mx3.hotmail.com[xx.xx.xx.xxx] said:
550
Requested action not taken: mailbox unavailable (in reply to RCPT TO
command)
Question:
Why the different behaviors? i.e. in one case I receive mailer
daemon message whereas in other an exception in SendEmail method?
Also,
To be specific how do mailer daemon messages work? Because as per the
second message it seems it was the relay that sent it.
If this is a configuration difference then what are they?

5.7.1 Unable to relay - this means that the message was addressed to an user in a different domain and the mail server could not "relay" it (basically, it cannot send it to another domain
The second error "mailbox unavailable" - this means that the Server has determined that the domain belongs to the Server and it has determined that there is no mailbox
So, it looks like in the first case, it is different domain and in the second case, it is the same domain.

Related

Using SmtpClient, and getting "the target machine actively refused it"

I am trying to use System.Net.Mail for an application to send an email, but get this exception:
System.Net.Mail.SmtpException: Failure sending mail. --->
System.Net.WebException: Unable to connect to the remote server --->
System.Net.Sockets.SocketException: No connection could be made
because the target machine actively refused it 198.238.39.170:25
The code I am using is:
string mailserver = "Scanmail.ofm.wa.lcl";
MailMessage msg = new MailMessage("albert#einstein.net", "snark#snarky.com", "Very subjective", "A message body!");
SmtpClient client = new SmtpClient(mailserver);
client.Send(msg);
Obviously the email addresses above are fictional, but in the actual code it uses real email addresses in the system. The mail server address is accurate.
I am tempted to think that I need to put some kind of security credentials in there, but not sure where - although #Andre_Calil's advice suggests this is not the problem, and that possibly the mail server is configured to prevent my development machine from connecting. So how is this to be overcome?
So, as we were talking, your server is probably configured to deny relay from every machine, which is a recommended security setting.
From your development machine, open a prompt (command) and type telnet SMTP_SERVER_IP_ADDRESS 25. This command will try to stablish a basic socket connection on port 25, which is the default SMTP port. If it's successful, you'll still have to discover whether the server requires authentication.
However, if it's unsuccesful, you'll have to put your code on hold until you can get the help of a sysadmin.
One other thing to try is to repeat this same test from a app server, because the SMTP server may be configured to allow app_server and deny everybody_else.
Regards

Error sending mail which states my IP has been blacklisted

I am continously sending mails from different addresses, and I haven't had any problems so far.
Now I am sending a new mail (just ONE email), and in the client.Send(message) line it throws an exception;
{System.Net.Mail.SmtpException: El buzón de correo no está disponible. La respuesta del servidor fue: 5.7.1 Mail refused, your IP is blacklisted - See http://www.spamhaus.org/query/bl?ip=+186.49.3.153
I have been looking around but have had no luck. I have never sent an email from this address, but if I change the credentials and try sending from another account, I have no problem.
I followed the link, and looked up for the ip address in the message error (186.49.3.153). This link leads to the page where it says that the IP is listed on the Policy Block List (PBL). I read the description, saying that if I am using any normal email software (Outlook, Entourage, etc) then it is simply because I need to turn on "SMTP authentication".
However, this is not the case since I am sending emails using .NET. Any ideas of what I should do?
Your mail server IP is being blocked (as the website provided will show).
The webpage explains why you are blacklisted.
Its also possible if your not on a static IP that you are using an IP that someone else has caused to blacklist.
For what ever reason you are blocked, there is an option provided to unblocking your IP. Just follow the instructions, and you should be up and running again shortly.

Throwing Exception while sending Email to multiple recipients using smtp client

I have an application which uses SmtpClient to send an email. I am trying to send an email to multiple recipients. I have two recipients in my to list e.g "aman#gmail.com,abc#xyz.com". and I am trying to send the email to this list but my application is throwing the exception as below:
Client does not have permission to submit mail to this server. The server response was: 4.7.1 (abc#xyz.com): Relay access denied.
because of this aman#gmail.com is also not able to receive the email.
I need to implement the functionality that even there is an invalid address like abc#xyz.com in the ToList, an email should be sent successfully to aman#gmail.com.
Can anybody please help me in this?
Does this error message come from your own email server, or from that of xyz.com? I'm guessing it's your own server, and that you either need to aunthenticate before sending, or use your own email address for sending (but the latter is kind of a long shot -- "we do not relay" means a server which is neither the sender's or the recipient's refuses to act as a middleman). It is also possible that the mail exchanger for xyz.com is misconfigured (either the MX record in DNS points to the wrong server, or the admin failed to configure it to accept this responsibility - technically basically the same thing) or that your client somehow ends up connecting to the wrong place.
(Not a proper answer but this got too long to fit in a comment.)

c# programmatically reading emails from the Exchange server

When you search on web you will find very easy answers for "How to read emails programmatically"... Al the websites are explaining most of the same like this page.
http://omegacoder.com/?p=454
// depends from Exchange server version
service.Credentials = new NetworkCredential("MDR", "password", "zzz");
service.AutodiscoverUrl("mdr#zzz.be");
object o = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
foreach (Item item in findResults.Items)
{
Console.WriteLine(item.Subject);
}
it fails when it executes the autodiscoverURL line. The error says "The Autodiscover service couldn't be located."
So I googled further and found this site from Microsoft https://www.testexchangeconnectivity.com/#&&/wEXAQUBcwUBME93h2+JjI0+MV2gTqcRL0g43z9m Here you can test your mail server....
When I pass the parameters I get the error below....
But I still don't understand what the problem is? Do I need to add a record to DNS ? Can someone help?
Attempting to test potential Autodiscover URL https://autodiscover.zzz.be/AutoDiscover/AutoDiscover.xml
Testing of this potential Autodiscover URL failed.
Test Steps
Attempting to resolve the host name autodiscover.ncb.be in DNS.
The host name resolved successfully.
Additional Details
IP addresses returned: 213.246.192.205
Testing TCP port 443 on host autodiscover.ncb.be to ensure it's listening and open.
The specified port is either blocked, not listening, or not producing the expected response.
Tell me more about this issue and how to resolve it
Additional Details
A network error occurred while communicating with the remote host.
Exception details:
Message: No connection could be made because the target machine actively refused it 213.246.192.205:443
Type: System.Net.Sockets.SocketException
Stack trace:
at System.Net.Sockets.TcpClient.Connect(String hostname, Int32 port)
at Microsoft.Exchange.Tools.ExRca.Tests.TcpPortTest.PerformTestReally()
Attempting to contact the Autodiscover service using the HTTP redirect method.
The attempt to contact Autodiscover using the HTTP Redirect method failed.
Test Steps
Attempting to resolve the host name autodiscover.zzz.be in DNS.
The host name resolved successfully.
Additional Details
IP addresses returned: 213.246.192.205
Testing TCP port 80 on host autodiscover.zzz.be to ensure it's listening and open.
The port was opened successfully.
ExRCA is checking the host autodiscover.zzz.be for an HTTP redirect to the Autodiscover service.
ExRCA failed to get an HTTP redirect response for Autodiscover.
Additional Details
A Web exception occurred because an HTTP 404 - NotFound response was received from IIS7.
Attempting to contact the Autodiscover service using the DNS SRV redirect method.
ExRCA failed to contact the Autodiscover service using the DNS SRV redirect method.
Test Steps
Attempting to locate SRV record _autodiscover._tcp.ncb.be in DNS.
The Autodiscover SRV record wasn't found in DNS.
Tell me more about this issue and how to resolve it
You don't necessarily need to use the autodiscovery if you already know the address of your exchange server. Try the following instead (for more info, look here:
service.Url = new Uri("https://hostname/EWS/Exchange.asmx");
Replace "hostname" with the hostname for your exchange server.
I hope you should have the solution by this time now. This is just to help anyone bumped on this post.
I found the solution on one of the technet article, I twick to suite me, and is working fine for me.
Just replace the line in your code with following:
service.AutodiscoverUrl("user#yourdomain.com",
delegate
{
return true;
});
I had some other issues but not related to this bit though.
Happy Coding,
Sanjay.
I had the same issue with AutoDiscover. It's not necessary, you can specify your URL like
Uri myUri = new Uri("https://Hostname/ews/exchange.asmx");
userData.AutodiscoverUrl = myUri;
service.Url = myUri;
As the hostname you can put the Server IP address like 192.168.100.10
Alternatively, to find what your Exchange server hostname is (in in fact the whole url to use) if you are using Outlook, go to your computer start bar, where the Date and time is showing, you will find the Outlook icon, hold Ctrl + right click on the outlook icon and click “Test Email Auto Configuration”
Check the "Use AutoDiscover" checkbox. Enter an email address hosted on that Exchange Server along with its password and you will recieve a bunch of url's. Use the 1 that says "Availability Service URL"
Consider that the credentials being passed need to have permission to the given exchange mailbox / server. In my case using a different set of credentials that are properly permissioned works but not for a service account which I'm trying to get to work.
Once I discover what exactly the account needs to be permissioned for I will update it here.
Update: My issue was the service account was from a domain different than the domain on which the exchange 2007 instance is running, even though there is a trust relationship between the two. I found this is a documented known issue in Exchange 2007 in how it looks up accounts in its forest. In the end had to create an identical service account (name/pass) on the domain on which the exchange server is sitting and specify username as {exchange_domain}{service_account_name}. The windows service that calls EWS runs as {original_domain}{service_account_name}.
For reference, the exception was:
Microsoft.Exchange.WebServices.Data.ServiceResponseException:
Failed to get valid Active Directory information for the calling account. Confirm that it is a valid Active Directory account.

SMTP Error Codes and determining if email is still delivered

I am using System.Net.Mail to to send mail. I do not know the type/version of the SMTP relay that it will connect to.
Some errors will result in no email being sent (e.g. no addresses or invalid from address) whilst others errors will still result in an email being sent.
E.g. Send To : bob#somewhere.com CC: fred#somewhere.com and DoesNotExist#somewhere.com may result in an error of
The server response was: 550 #5.1.0 Address rejected DoesNotExist#somewhere.com.
But the email still appears to be delivered to Bob and Fred.
Is there any reference to which error codes will still result in an email being delivered or any programmatic way of determining this?
This is the way that SMTP operates, as described in the RFC.
Failure to deliver to one recipient does not affect delivery to other recipients.
Generically, codes starting with 4 and 5 are failures, codes starting with 2 are success codes - see RFC821 section "4.2.2. NUMERIC ORDER LIST OF REPLY CODES".
"Email being delivered" is hard to define. Email being accepted for delivery by the SMTP server is defined by the SMTP protocol (and the server will signal acceptance to deliver a message) but this server might just relay the message to another server, or operate in a smart host configuration where it just accepts messages and passes them on to the smart host - delivery is another thing and it's usually associated with local delivery (LMTP).
Some mail clients work around this problem of not being able to tell if a message has been delivered by implementing the dreaded read receipts - but this implementation is entirely on the client side and AFAIK it has nothing to to with SMTP.
RFC 821 is the one that describes SMTP and includes information about different types of errors, but not sure if it contains the details you're looking for. And either way, even if you can find out that the mail server accepted the email for some users, that is not the same as saying that it was delivered to them.
As far as I know, there is no way of telling if an email has been delivered except if the recipients mail client will tell you in some way.
Non-delivery reports (NDRs) are system messages that report the delivery status of a message to the sender. The messages are a subclass of a general message information structure that is referred to as delivery status notifications. Delivery status notifications describe three different types of situations:
* Success (2.X.X numeric codes)
* Persistent transient failure (4.X.X numeric codes)
* Permanent failures (5.X.X numeric codes)
To learn more about delivery status notifications, see Request for Comment (RFC) 1891 and RFC 1893.
Qouted from Microsoft Support http://support.microsoft.com/kb/284204

Categories