How to get back DeliveryNotificationOptions in Message in c#? - 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?

Related

Send email from C# WPF app without external SMTP

I need to find a way to send e-mails from my WPF application. Of course I tried sending it using for example Gmail SMTP and it works like a charm but for some reason this solution is unacceptable. So is there a way to send email straight from my computer without using any logging credentials or additional/not open source software? I tried something like this:
SmtpClient m = new SmtpClient();
m.Host = "xxx.xxx.xxx.xxx"; // my IP address.
m.Port = 25;
m.Send("Tests#xxx.xxx.xxx.xxx", "tests#gmail.com", "Test", "This is a test email.....");
It doesn't work like that, I've put mu IPV4 addres from ipconfig but the error I got is:
No connection could be made because the target machine actively refused it.
Is this even possible to run this straightforward from my PC like that? I assume its not even my static IP but some kind of dynamically changed IP from my ISP hidden behind NAT. How to configure it in other way?
My app is expected to run for example overnight and then I would like to receive and email after process is finished. Not interested in receiveing any other emails or sending emails to multiple users.
Sending email via SMTP is not complicated is just very legislated.
Each mail provider gmail/office365 has a configuration which you must follow exactly. The configuration is not even to send the email its just to autorize yourself for the smtp account being used.
Doing a quick search online for gmail the conditions are currently::
https://support.google.com/mail/answer/7126229?visit_id=1-636683482170517029-2536242402&hl=es&rd=1
Good luck

Exchange Transport Agent Bounce MailItem

In our Exchange RoutingAgent, we would like to be able to bounce an email back to the sender in the event of an unexpected exception. We would also like to be able to send the bounce message to some pre-defined admin email too if possible. Is there any way to bounce a message in the OnSubmittedMessage or the OnResolvedMessage events? I am hoping there is some method in the Exchange libraries to easily achieve this, or is there some way to create a new MailItem and send it to the original sender and possibly an admin?
You need to generate a new message to do that there is a sample for this on https://blogs.msdn.microsoft.com/mstehle/2010/03/10/howto-return-to-sender-transport-agent-sample/
You should also be able to use https://msdn.microsoft.com/en-us/library/jj976002(v=exchg.150).aspx
Cheers
Glen

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

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

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

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

Categories