I use the smtp for sending mail from my application , I want to catch the error when the mail address is valid but inexistent but the method didn't catch even i implement this code:
catch (System.Exception exp)
{
if (exp.GetType() == typeof(SmtpFailedRecipientException))
{
//// display error message
}
}
What should i do?? Is SmtpFailedRecipientException didn't recognize inexistent address mail??
SmtpFailedRecipientException Represents the exception that is thrown when the SmtpClient is not able to complete a Send or SendAsync operation to a particular recipient. MS Link
I assume it's an external SMTP client , so when sending the mail
,it will not validate external mail address immediately. It is later after
the external node send back error message will it popup message sending
fail error. The SmtpClient component will close the communication with
server right after the message has been sent out, but not trace the
sequential message delivery status. MS Answer
In order to work fix your problem there are couple of things you can do :
Try an external library Here's a link for a good one
Create your own SMTP socket program Here's another link
Related
References to this link, I understand how to send email to many recipients my question is if one of them fail this mean Send(Msg) will throw error for all ? or just for specific recipient appreciate any help thanks
Assuming you are using System.Net.Mail.SmtpClient.Send(MailMessage), the documentation shows that it can throw a "SmtpFailedRecipientsException" exception when the message could not be delivered to one or more of the recipients in MailMessage.To, MailMessage.CC, or MailMessage.Bcc.
The SmtpFailedRecipientsException exception has an InnerExceptions property.
Gets one or more SmtpFailedRecipientExceptions that indicate the e-mail recipients with SMTP delivery errors.
https://msdn.microsoft.com/en-us/library/swas0fwc(v=vs.110).aspx
Note: Depending on the issue, the SMTP server may accept the message and fail to deliver it to the recipient further along in the process.
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.
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.
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.)
I used smtpclient to send emails, but finally i found that some of the emails can not be reached.
for example:
receiver: aaa#123.com
sometimes, the emails we send to it , and it will receive successfully, but sometimes will not.
at the beginning, I thought it might because that smtp didn't send it successfully, then I use client.sendAsynce, and then add the event handler to handle the SendCompleted event, and i found every emails are sent out successfully, and then we check the smtp server, it really received all the emails and sent out successfully.
So the problem is why sometimes the emails will not be reached successfully, and sometimes will be OK?
You're forgetting one piece of the puzzle - the client email server. Perhaps the emails are being rejected or flagged as spam?