Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error message sending email via SMTP client

Posted on 2011-03-11
1
Medium Priority
?
605 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
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…

721 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