Solved

Error message sending email via SMTP client

Posted on 2011-03-11
1
590 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

863 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

22 Experts available now in Live!

Get 1:1 Help Now