Send Email on GMail SMTP under medium trust
Asked Answered
O

4

10

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?

Osanna answered 11/5, 2009 at 12:39 Comment(1)
Bounty because I would like to know how to send an e-mail under medium trust now that port 25 is almost always blocked.Calling
D
4

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

Deaminate answered 15/7, 2009 at 10:12 Comment(0)
M
1

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.

Mannino answered 7/5, 2012 at 19:37 Comment(3)
The web service is a great idea but I have nowhere to host it. Perhaps one exists already...Calling
You can add a subdomain to your existing website?Mannino
Not possible with the hosting I use. It's a shared medium trust hosting. Even if it was possible, the subdomain would have the same restirctions.Calling
C
1

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:

Cheongsam answered 13/5, 2012 at 19:51 Comment(1)
Good answer but unfortunately this does not work with the current hosting.Calling
A
1

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.

Alpaca answered 14/5, 2012 at 17:48 Comment(2)
Seems so stupid never to have thought of this. This was the solution.Calling
I've had this come up before. Glad I could help!Alpaca

© 2022 - 2024 — McMap. All rights reserved.