10
votes

I need to send an email from my app, which will be running under medium trust. My current email sending code that works fine under full trust throws SecurityException under medium trust

[SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]

Examining my machine.config and allied files reveal that my SMTP access is restricted to Connect.

<SecurityClass Name="SmtpPermission" Description="System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

and

<IPermission class="SmtpPermission" version="1" Access="Connect"/>

According to MSDN, Connect allows request on port 25 only. But Gmail servers work on port 587. Any workarounds? suggestions?

4
Bounty because I would like to know how to send an e-mail under medium trust now that port 25 is almost always blocked.MarioDS

4 Answers

4
votes

Gmail also Accepts Port 25 ; you just give Port 25; its Working For Me.,

1
votes

Have you tried port 465.

http://support.google.com/mail/bin/answer.py?hl=en&answer=13287

You could also create a web service, and send the email from your app into the web service. Then run the web service with full trust.

1
votes

In medium trust, yes, you are "stuck" with Port 25. If you can/have access to (am referring to your web host) to create custom config files:

<IPermission class="SmtpPermission" version="1" Unrestricted="true" />

References:

1
votes

Often times the web host wants you to use their own SMTP server for your outbound emails. I don't know if that would present a problem with your particular scenario, but if not, you should probably contact the host and ask them what their SMTP server is, instead of trying to use an external one.