system.net.mail

asp.net net.mail - route all emails to a different email address in debug mode

本秂侑毒 提交于 2019-12-06 01:15:17
Is there anyway to have all emails go to a different address when System.Web.HttpContext.Current.IsDebuggingEnabled is true? Or do I need a new class which I use to send email everywhere? We use a similar solution to the MailProxy method detailed by tvanfosson. However we have a few differences that I feel are worth mentioning. The first is that we simply extend the SmtpClient class and override the Send methods when in a development or testing environment. We use a config file to determine the environment. We then use this class anytime we need to send out emails. This class will determine

How to programmatically store (save) SMTP server details back to web.config

北城以北 提交于 2019-12-05 16:20:13
Searching StackOverflow, I found this question on how to Retrieve SMTP settings from Web.Config , but no details on how to update the SMTP back to the web.config file. I started with the following code: Configuration webConfig = WebConfigurationManager.OpenWebConfiguration("~"); MailSettingsSectionGroup settings = (MailSettingsSectionGroup)webConfig.GetSectionGroup("system.net/mailSettings"); SmtpSection smtp = settings.Smtp; SmtpNetworkElement net = smtp.Network; but was quickly clued in by Intellisense that SmptSection.Network is a Get (aka "read-only") accessor. So how am I supposed to

System.Net.Mail reference does not exist

北城余情 提交于 2019-12-05 10:35:16
I have a problem creating application to send email. I already have one working as a Windows Forms Application and then decided to do the same from the empty project, because I need to make a background application now. I used the System.Net.Mail namespace for that in a Windows Forms. Then added the same code to the new project. However, I get the following error: The type or namespace name 'Mail' does not exist in the namespace 'System.Net'. The 'System.Net' reference is included in the project references list and I can't find anything named 'System.Net.Mail' in the list of possible

Cant emails through exchange: An existing connection was forcibly closed by the remote host

若如初见. 提交于 2019-12-05 07:21:37
问题 I just noticed that some of the email operations in my code have been failing and am trying to fix it up, however I keep getting the following error: System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[]

Using System.Net.Mail in ASP NET MVC 6 project

风流意气都作罢 提交于 2019-12-05 01:17:16
I have trouble creating a simple mock mail sender within an ASP NET 5 project. Here the method : public static Task SendMail(string Email, string Subject, string Body) { SmtpClient client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; client.PickupDirectoryLocation = "C:\\TMP"; MailAddress from = new MailAddress("jane@contoso.com", "Jane " + (char)0xD8 + " Clayton", System.Text.Encoding.UTF8); MailAddress to = new MailAddress(Email); MailMessage message = new MailMessage(from, to); message.Body = Body; message.BodyEncoding = System.Text.Encoding.UTF8;

SmtpClient get result from server on send

不问归期 提交于 2019-12-04 02:50:47
问题 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 回答1: 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...

Cant emails through exchange: An existing connection was forcibly closed by the remote host

[亡魂溺海] 提交于 2019-12-03 21:13:49
I just noticed that some of the email operations in my code have been failing and am trying to fix it up, however I keep getting the following error: System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[]

Why can SmtpClient.SendAsync only be called once?

不问归期 提交于 2019-12-03 07:44:07
问题 I'm trying to write a notification service (for completely legit non-spam purposes) in .NET using SmtpClient. Initially I just looped through each message and sent it, however this is slow and I would like to improve the speed. So, I switched to using 'SendAsync', but now get the following error on the second call: An asynchronous call is already in progress. I read this to mean that MS crippled System.Net.Mail to prevent mass-mailers. Is this correct? If so, is there a better way to do this

Why can SmtpClient.SendAsync only be called once?

十年热恋 提交于 2019-12-02 20:29:43
I'm trying to write a notification service (for completely legit non-spam purposes) in .NET using SmtpClient. Initially I just looped through each message and sent it, however this is slow and I would like to improve the speed. So, I switched to using 'SendAsync', but now get the following error on the second call: An asynchronous call is already in progress. I read this to mean that MS crippled System.Net.Mail to prevent mass-mailers. Is this correct? If so, is there a better way to do this in .NET, and still be able to log the results of each email(which is important to our client). If not,

performance of bulk emailing using system net mail

元气小坏坏 提交于 2019-12-02 20:20:44
问题 I have been asked to look into a bulk emailer for an intranet system and wanted some advice. Currently we use System.Net.Mail and send the emails synchronously via the customers own smtp server, typically Microsoft exchange. If we were allow them to send emails to larger and larger groups what sort of pitfalls will I likely face? I have considered that I may need to look at sending them asynchronously, is it quicker to send one email to a large distribution list rather than an email to each