SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to show a popup-window with a basic e-mail layout and send the e-mail after pressing the send button. The popup, I've created and also the webpart within. But when I want to send the e-mail, it crashes at the following line:

SmtpClient client = new SmtpClient(SMTP_HOST, SMTP_PORT);

With SMTP_HOST and SMTP_PORT the settings from my exchange online account:

private const string SMTP_HOST = "";
private const int SMTP_PORT = 587;


System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at System.Net.Mail.SmtpClient.Initialize() at System.Net.Mail.SmtpClient..ctor(String host, Int32 port) at ...

Does anyone know what's my problem here?

share|improve this question
up vote 3 down vote accepted

You can't use the System.Net.Mail namespace or SPUtility.SendEmail with Office 365/Sandbox solutions.

SPSE - Send email via code in Office365

share|improve this answer
Is there any other way to send an e-mail (WITH attachment)? – Ruben Herman Jan 9 '12 at 9:01
For example a webservice? – Ruben Herman Jan 9 '12 at 9:07
You can't call an external service (such as a web service) from a sandbox solution either. Perhaps you could use some way of kicking off a workflow or use a full trust proxy. – Ryan Jan 9 '12 at 15:56
Did you come up with a workaround to this? – imoses Sep 25 '15 at 13:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.