Solved

Error message sending email via SMTP client

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface There are many applications where some computing systems need have their system clocks running synchronized within a small margin and eventually need to be in sync with the global time. There are different solutions for this, i.e. the W3…
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!
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

628 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