Error on testing mail settings

Topics: ASP.NET 2.0
Jul 15, 2009 at 5:34 PM

Hello I have just installed 1.5 and when I tested my mail settings under settings tab it gives me following error

Could not connect - Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I am using google apps service and have specified correct credentails for username password and port no. as 587 smtp server as and SSL is enabled

please tell me how to solve this error

Jul 17, 2009 at 2:27 PM

anybody has solution for this ?

Jul 24, 2009 at 5:22 PM

I am having the exact same issue. Also using google apps.

Jul 25, 2009 at 12:38 AM

I'm pretty sure this error happens when you specify a non-port 25 in a medium trust environment.  One of the quirky medium trust rules is that an SMTP port other than port 25 isn't allowed (full trust is required).

For Google Apps (or just Gmail), I'm pretty sure you can stick with port 25 even with SSL enabled and it will work.  If not, then try turning off SSL.  Either way, use port 25.

Jul 25, 2009 at 5:16 AM

I tried using port 25 but it doesn't work. Is there any seetings need to be done in web.config file ?

My blog is hosted on Godaddy servers. When contacted Godaddy support dey told to use relay server but when I used their relay server it can only send mail if mail id speciffied in email textfield in contact form is same as that configured at google apps.

If some visitor specifies an email id like or any else it doesn't send an notification mail to me

Jul 25, 2009 at 5:49 AM

sohin_shah: What version of BE are you using?

Just recently, there's been some changes to make sending emails out of BE work better.

In your contact.aspx.cs file, comment out or remove this line of code (the // comments it out).

//mail.Sender = mail.ReplyTo;

You may also need to comment or remove this line too (I would first try leaving it in).

//mail.ReplyTo = new MailAddress(email, name);

If you're still having problems, then post your email settings here.  There's no settings in the web.config file I can think of that would make any difference.

Jul 25, 2009 at 7:25 AM

I am using

Commenting either or both lines of code works seems strange what can be reason behind this

//mail.Sender = mail.ReplyTo;

//mail.ReplyTo = new MailAddress(email, name);

I can rec mail now but if you reply to that mail your own mail id will be mentioned in TO field (where mail has been sent to or own mail id) instead of mail id mentioned in email textfield in contact page

Jul 25, 2009 at 8:01 AM

Try leaving the mail.ReplyTo line in there.  Setting ReplyTo will make it so when you Reply, the email address of the person who left the Contact msg will be in the "To" field.

mail.Sender line is the main offender.  Oftentimes, shared mail servers don't like it when you try to set either mail.From or mail.Sender to an email address that is not managed by that mail server.  It wants you to put YOUR email address in either mail.From or mail.Sender.  Putting someone else's email address in mail.From can be thought of as spoofing.

And it's actually not even necessary to use mail.Sender because mail.From is already being set.

Jul 25, 2009 at 8:29 AM

have commented only mail.Sender line and now its shows visitors mail in reply-to header field but still on relpy will send mail to myself since mail.sender is not being allowed by server since you pointed it right that it can lead to spoofing and spamming and hence was showing System.Net.Mail.SmtpPermission error earlier

Thank you Ben for solving this issue