Cant send the text "0880" with .NET SmtpClient.Send() - c#

I bumped on this error while trying to help a developer resolve a bug.
He was having issues with mails that were supposedly send but never arrived. Checking the code and the msg we came to the conclussion that the text that was caousing the issue was "0880". So i made a test page with a button and the following code on it:
SmtpClient cl = new SmtpClient("exchangeserver");
cl.Send("mail#from.com",
"mail#to.com",
"Test",
"0880");
Much to my surprise even thou the Send function executes and doesnt throw an exception the mail never arrives. If i replace the text in the body with other string, say "this is a test mail" the mail arrives fine.
I tried using MailMessage class with the Send() with and without HTML, i even tried using gmail smtp server instead of my company exchange server, but the result its always the same the mail with the 0880 never arrives, all the other strings ive tried do.
Any ideas?
Thanks

Related

How to get back DeliveryNotificationOptions in Message in c#?

I created an application which sends mail but want to know if some of the mail has failed. How could I know that? I try to use code
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
but it just sends through my online mail delivery, I want to see those in application over the Message.Show. Is there any simple way to do that?

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.)

SmtpClient get result from server on send

The SmtpClient send method returns void. Is there any way to get the server response? Do I just assume it was successful unless it throws an exception?
The class I'm referring to... http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
To answer your second point, yes, all you can do is assume it's successful - meaning it got the message to the server and the server accepted it, unless you get an exception.
You probably already know the rest of this, but just in case...
From there, the email could get lost and not delivered any number of ways. Your server may accept it and decide not to send it, or accept it and lose power before crashing. It may get blocked by a spam filter along the way, etc.
You can think of an email as being similar to a regular piece of mail in that it passes through several hands between the sender and the recipient. From your code, you can only confirm that it got to the SMTP server you're using to send, which is similar to handing it to a teller at the post office. You don't know (or need to know) how the message is routed from there. it could be by air, ground, or carrier pigeon. You're out of the equation - you don't need to know how it gets sent, just that you trust that they know how to send it. (The same can be said for an email.)
If you need to confirm that the recipient opened it, there are ways of embedding an image in an HTML message on your server and tracking in your logs when that image is accessed, etc. (Google email tracking and email open tracking)
On the other hand...
If the server rejects it, then you do get a server response in a manner of speaking - there should be an error code and a description in the error, which you can use to troubleshoot why it didn't make it, or use error handling to try another route, etc.
You can utilize SendCompleted Event to check that your smtpclient works fine like this:
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.sendcompleted.aspx
But you cannot get confirmation that your message reached recipient because it may stuck in any server/filter in message chain.
You assume that it was successful unless it throws... although success in this case only means that it was accepted by the mail server, anything else is then up to the server...
IF you want a little bit of control you can use SendAsync and hook the SendCompleted event...

Mail doesn't get send untill I terminate my application - System.Mail.Net

I have written some simple code, to send en auto generated email, using the System.mail.Net namespace.
It works like a charm, but there is one little problem.
The mail does not get send, untill my whole application is terminated.
Does any of you have a workaround for this?
Here is the code I use (c#):
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("myEmail#mail.com");
mail.To.Add("targetEmail#mail.com");
mail.Subject = "Test test";
mail.Body = "blah blah";
mail.Attachments.Add(new Attachment("c:\\file.txt"));
SmtpClient smtp = new SmtpClient("myserver.mail.com");
smtp.Send(mail);
}
catch (SmtpFailedRecipientsException ex)
{
Console.WriteLine(ex);
}
As I said, everything works, but the mail is not send, untill I terminate the application.
Is there any way to force it to send the mail now?
The reason it is a problem, is both that I want the mail to be sent instantly without the user needing to reboot the application, but also because I want to delete the attachment after the mail has been sent, and when the mail isn't sent, the file is therefore marked as "in use" and can therefore not be deleted.
Best regards
/S
I've had the same problem, and using the workaround posted at http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/6ce868ba-220f-4ff1-b755-ad9eb2e2b13d/ seems to work:
For anyone interested, I've found a solution or at least a work around to the delay.
The ServicePoint member contains a member called MaxIdleTime. Setting this value to 0 seems to have the same affect as Timeout.Infinite (which I assume is also 0). Setting it to 1 caused my email to be sent out immediately.
See this link:
http://msdn2.microsoft.com/en-us/library/system.net.servicepoint.maxidletime.aspx
Example code:
SmtpClient smtp = new SmtpClient();
// setup the mail message
smtp.ServicePoint.MaxIdleTime = 1;
smtp.Send(myMailMessage);
Calling
smtp.Send(mail);
Sends the email to your smtp server immediately. If you're not seeing the email being sent as soon as that line executes, then I would check to see if your smtp server is functioning properly.
Here's more information on the SmtpClient.
I wonder if your application has a lock on the attachment which is preventing the mail component from doing its work until your application starts shutting down. Can you verify that all locks are cleared prior to sending the mail?
You might start with a new small app that only sends an email. Once that it working properly, add a hard coded attachment. Verify it's still working. If everything is good, add your code for how you are handling attachments. If it breaks, tweak your code. Rinse and repeat. ;)
I have seen this problem before. I had to turn off Norton Antivirus outgoing email scan to get emails to go right away.
HTH

why some emails can not be reached?

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?

Categories