Solved

Error message sending email via SMTP client

Posted on 2011-03-11
1
588 Views
Last Modified: 2012-05-11
On one of my customers computers, I get the following error trying to send email:

Unable to create SmtpClient due to missing permissions. If you are using a port other than 25 for your email server, SmtpPermission has to be explicitly added in Medium Trust.

Has anyone seen this before and how do I fix this?

Thanks!
0
Comment
Question by:droseblade
1 Comment
 
LVL 14

Accepted Solution

by:
Tribus earned 500 total points
ID: 35115040
According to this article on MSDN SmptClient should work in Medium Trust.

Unfortunately my first tests trying to use SmtpClient in Medium Trust ended up failing with:
Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Checking several other sources too, seem to point out that this should work in "medium trust".

Sending through SmtpClient does work in Medium Trust as long as you stick to the default email port of 25.  My ISP requires me to send email through an alternate port 2525 when I'm not connecting through their network.  Using a different port still makes SmtpClient fail with a security permission error.  I suppose this requirement makes some sense but it's neither documented nor is it obvious.  Neither does the error message or call stack offer any indication of any problem.

To get around this issue with a custom port I still have to use a custom policy definition and add:
<IPermission class="SmtpPermission"

            version="1"

            Unrestricted="true" />

Open in new window


Into the custom permission set defined.

My ISP has recently dropped the custom port requirement for external email access, so to my surprise, I found I actually can send email on the stock port of 25, which worked without any problems.  Apparently the custom port configuration has been a big hassle for the ISAP on the maintenance end as customers call and wonder why their email access doesn't work when they're traveling and so they opened direct port 25 access again. But, there are still a number of ISPs that follow this practice, so this remains a potential issue and it's something to be aware of in a generic solution.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now