Solved

Error message sending email via SMTP client

Posted on 2011-03-11
1
601 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
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…
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…

751 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