Send Email when Error in ASP.Net MVC 5 using ELMAH - asp.net

I am trying to send email whenever there is an exception in my code using Elmah.
Here is the configuration in web.config file.
<elmah>
<errorMail from="MyEmailId#gmail.com" to="MyEmailId#gmail.com"
async="true" smtpPort="0" useSsl="true" />
</elmah>
<system.net>
<mailSettings>
<smtp deliveryMethod ="Network">
<network host="smtp.gmail.com" port="587" userName="MyEmailId#gmail.com" password="MyEmailPassword" />
</smtp>
</mailSettings>
</system.net>
Now above configuration works fine. I tested in localhost every time I get an exception I am getting an Email Successfully.
Question 1:
Does that mean if I deploy my application with above settings, no
matter who ever access my website, if they get an exception I will
receive an email.
Question 2:
I have added password in above config file. But now everyone can see
my password. Is this the right way or I can still send the mail w/o
putting my password in config file.

Answer to question 1 :
Exceptions will be caught irrespective of the type of error module you
use. So you will definitely receive an email in those exception cases.
Answer to question 2 :
Why are you using your personal mail id? Create a new ID and use it
for the purpose, so that even if others see, it doesn't have any
effect. Others means only the developers will be able to see, not the
public. You can encrypt the web.config file by checking this MSDN
article.
Also consider encrypting your password and storing it in the
web,config file.

Related

<MailSettings> Use deliveryMethods 'Network' and 'SpecifiedPickupDirectory' simultaneously

Exactly as it says on the tin: is it possible to specify both delivery methods in a single configuration? I'd figure it'd be a quick (and cheap) solution to log all e-mail messages that were sent directly by the standard .NET SmtpClient.
What I'm trying to achieve here is a solution in which every e-mail sent by an defaultly SmtpClient instance is both submitted directly to a configured SMTP server and stored in a pickup directory, which merely will act as a storage point for logging the sent e-mail messages.
In other words: Is a configuration as follows possible?
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="source#domain.com">
<network host="127.0.0.1" />
</smtp>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="C:\SmtpLog" />
</smtp>
</mailSettings>
</system.net>
Don't believe this is possible in the manner you suggest - see Scott Gutherie's response on http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx (search page for "multiple SMTP servers"). Old message but still current from what I can tell.
I think the system.net mailSettings in web.config are supposed to be considered the default settings.
However you can do it in code easily enough (plenty of examples out there) and you could do it so that you can configure in web.config using custom settings.

umbraco email form not working with gmail smtp

I am trying to get the Cultiv Razor contact form working, but am not having much luck. I've read that you can use GMail as an smtp relay (found some solutions here, in the documentation, and on the umbraco forums which outline how to do it) but I can't get it to work. here's what my web.config looks like (masked out the user id and password here):
<mailSettings>
<smtp>
<network host="smtp.gmail.com" port="587" userName="xxxxxx#gmail.com" password="xxxxxx" defaultCredentials="false" enableSsl="true" />
</smtp>
</mailSettings>
and I am using a completely stock install of cultiv contact form. Here's my macro code directly on my template:
<umbraco:Macro MailFrom="xxxxxxx#gmail.com" Alias="Cultiv" EnableSsl="true" runat="server"></umbraco:Macro>
I have tried it with and without the ssl setting, and have tried with and without the #gmail.com part of the address. Every time I try and test the form, it reloads the page, appends #cultivcontactform to the end of the URL, the form disappears, and the following is added to the umbracolog table:
Error creating or sending contact mail, check if there is a mailFrom property on your document and that it has a value, or specify a MailFrom parameter on the macro call exception:
I'm stumped on this and have been for a while. I'm using Umbraco 4.11.10
Any suggestions for further troubleshooting would be much appreciated.
It is possible that the installation of the package wasn't complete, can you please check the macro-property "MailFrom" on the "Cultiv" macro?
Even if you specify the value in the umbraco:Macro tag, the macro-property has to be saved on the Macro itself.
Or, as the error suggests, add a property on your document type with the name "mailFrom" and save it with your email address.

System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable.

I get this error when trying to send an email using Asp.net application using SMTP on IIS 7.5
The error is "System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: No such user here at System.Net.Mail.SmtpTransport.SendMail(... "
What i have in web.config is
<system.net>
<mailSettings>
<smtp from="support#mysite.com" deliveryMethod="Network">
<network host="hostname" port="25" password="password" userName="you#yoursite.com" />
</smtp>
</mailSettings>
</system.net>
I really don't understand what should be the username and password here. I get the same error when i put defaultcredentials = "true" instead of username and password. Is there something to do with toaddress. The toaddress is myid#mydomain.com, which works for all other emails, etc.
Please advice me where i am doing wrong!! Thank you in advance!
The userName and password settings refer to the credentials for connecting to the SMTP server. Make sure you don't confuse this with the username and password for the from or to address, which is not relevant to the SMTP server.
You may want to try a tool like SMTPDiag to help you figure out any SMTP connectivity issues you have. However, your error seems to indicate that connectivity is fine but that mail cannot be delivered.
Ram if you are using a web host and you have SMTP support in your package... Then check their control panel.
Also as Jacob I want to remind you that FREE SMTP user accounts that web hosts offer are different from credentials to connect to the SMTP server itself. Usually the former is that's free with web hosts and the latter is not included as long as you don't have a dedicated server I think.
If you don't find it in their control panel then call support... They will be able to give you those details if applicable.

Smtp Config in asp.Net

Hai,
I have developed small asp.net application.i send mail through this application.so my web config file have following coding
<network host="smtp.gmail.com" port="587" userName="username#domainname.com" password="*****" />
</smtp>
</mailSettings>
we have google apps.we don't have mail server.
i try to sent mail,i getting time out error.
regards
mariyappan.J
If you are using System.Net.Mail.MailMessage try this:
yourMailMessage.EnableSsl = true;
This could be:
Firewall related
IIS User account related
Have you tried smtp.googlemail.com Reading this it doesn't matter
I realise that's a bit of a generic answer but your config settings are correct so logically it can only be related to the network, or the user.

SMTPClient Half Working \ Half Not

I am using Microsoft's membership framework on a website. I am able to send password retrieval e-mails, but am unable to send e-mails myself using SMTPClient.
When you configure the SMTP settings in the Web Site Administration Tool, what are the settings that this application give it's SMTPclient?
If I know this, I can duplicate it and hopefully send e-mails.
A few items I've ruled out.
- I'm using port 25, (which is the only one allowed under medium trust).
- This code works on my local system.
I was attempting to pass the values for SMTPClient in with the constructor. What I failed to realize is that SMTPClient apparently automatically pulls the values from web.config and uses those.
By trying to pass my own values (even though they where identical); I inadvertently violated trust levels causing a security exception.
Don't pass in smtp info in the constructor, use web.config to set it up, and there should be no problem in medium trust.
It could be lots of things, from credential problems, DNS issues, or...who knows. Is it unable to send as in you get an error or as in they appear to go but never arrive?
Are you sure the WSA tool is going through SMTPClient, or are you just assuming it (I don't know myself)?
-- MarkusQ
I am getting a Security Exception on
my mail
That sounds like a credentials problem then, or a trust issue. Are you sure you're running at medium (or higher) trust? What's the rest of the error?
-- MarkusQ
Try checking your web.config file: is the WSA tool updating these settings?
This element is under the configuration element
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="you#email.com">
<network
host="your.gateway.com"
userName="your#email.com"
password="your_password"
port="25" />
</smtp>
</mailSettings>
</system.net>

Resources