Use both send and pickup directory method for SMTP mailSetting - c#

Current system that I working on has a email sending function with this configuration in Web.config as below
<mailSettings>
<!-- Method#1: Configure smtp server credentials -->
<smtp from="some-email#gmail.com">
<network enableSsl="true" host="smtp.gmail.com" port="587" userName="some-email#gmail.com" password="valid-password" />
</smtp>
<!-- Method#2: Dump emails to a local directory -->
<smtp from="some-email#gmail.com" deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" />
<specifiedPickupDirectory pickupDirectoryLocation="~/App_Data/EmailPickup" />
</smtp>
</mailSettings>
As the config shown about there is 2 method, but it only able to enable 1 method in a time, else it will cause error when i try to run the system.
Question: it there any config or setting can make both of the method work at the same time?
I want it send the email as well as pickup the email and drop it into the folder i specific on.
I was able to manually create a file with StreamWriter and save into folder but it require extra code to handle it.

Related

Web Config Error Causing 500 Internal Server Error

I have this inside my Web.config:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="admin#xxxxxx.com">
<network defaultCredentials="false" host="mail.xxxxxx.com" password="xxxxxxx" port="25" userName="admin#xxxxxx.com" enableSsl="false" />
</smtp>
</mailSettings>
</system.net>
This causes any request to my website becomes
500 Internal Server Error
This makes the hosting server assumes that my Web.config is not valid. Before it was fine, my Web site can run with no problem. I cannot see any syntax error in it?
What is going on here?
Posting from comment thread as answer: You likely have a special character in your password that may require XML encoding.

Can't send mail from server

We built an ASP.NET app that we deployed on the client's server, using their SMTP server.
I'm trying to have Elmah send error emails using the ErrorEmailModule. This uses the SMTP settings as configured in the web.config, but somehow sending emails is not working (nothing is being sent).
The SMTP settings are configured like this:
<system.net>
<mailSettings>
<smtp from="support#xxxxxx.nl">
<network host="xxxxxxx.management.local" port="25" enableSsl="true" defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>
To test if this is a problem with Elmah or with the config I created a little test application that uses the same setting and tries to send an email:
string from = "support#xxxxxxxx.nl";
string to = ConfigurationManager.AppSettings["ErrorReportingEmail"];
var message = new MailMessage(from, to, "Test", "Test");
var smtpClient = new SmtpClient();
smtpClient.Send(message);
This doesn't work either. SmtpClient doesn't throw an error, it just acts like it sent an email, but I'm not receiving anything.
I then tried sending an email using 2 different email testing tools, called MailTester and MultiMail, I entered the same SMTP settings, and they can send emails just fine.
So my question is: why can I send emails from these mail tester apps but not from my ASP.NET app?
try this set deliveryMethod = network.
<system.net>
<mailSettings>
<smtp from="support#xxxxxx.nl" deliveryMethod="Network">
<network host="xxxxxxx.management.local" port="25" enableSsl="true" defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>

Password recovery in asp.net c# web forms application works on localhost but not on Godaddy server

I have an asp.net c# web forms application that utilizes the password recovery control. The password recovery sends an email with a new password when running it on my localhost. But when I try it from my Godaddy server it times-out.
Here's what I have:
Basic password recovery control:
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server"></asp:PasswordRecovery>
web.config file has:
<mailSettings>
<smtp from="me#gmail.com">
<network host="smtp.gmail.com" password="mypwd" port="587"
userName="me#gmail.com" enableSsl="true" />
</smtp>
</mailSettings>
What do I need to do in order to get this working on GoDaddy?
I decided to use Godaddy (secureserver) email instead of Gmail. To get this to work simply change the web.config file to:
<mailSettings
<network host="relay-hosting.secureserver.net" />
</mailSettings>

What is the purpose of specifying from attribute in smtp element?

When sending mail using system.net. Having specified from attribute in system.net->mailsetting->smtp. In send method we have to pass from address once again, so what is the purpose of specifying it in the config?
<smtp deliveryMethod="Network" **from="xyz#xyz.com"**>
<network host="smtpout.secureserver.net" port="80" userName="xyz#xyz.com" password="xyz-password" />
</smtp>
If the from address never changes, this is a good place to set it.
Many applications send email from a single account, so configuring it there instead of hard coding it makes sense.
This value is used in the parameterless constructor of MailMessage.

Sending mail with ASP.NET

I use the standard web.config 'mailSettings' as the backbone for my ASP.NET emails. However, I find it to being increasingly limited in capability. For example, I want to send emails from many different user accounts (support, sales, management etc.) and it doesn't seem like mailSettings supports this. Is there any way to avoid using mailSettings so that I can use multiple accounts? Any disadvantages (and if not, then why would anyone use mailSettings?)
<mailSettings>
<smtp from="support#company.com">
<network host="smtp.gmail.com" port="587" userName="support#company.com" password="abcPassword"/>
</smtp>
</mailSettings>
If you're sending your mail using a System.Net.Mail.MailMessage, you should be able to override the From in the web.config by setting the MailMessage.From to a new MailAddress.

Categories