4

Is it possible to send an Email from an Autohosted Sharepoint 2013 app from CSOM code (C#) with an attachment?

I have the following code:

 EmailProperties properties = new EmailProperties();
            properties.To = new string[] { "[email protected]" };
            properties.Subject = "Subject";
            properties.Body = "Body";

            Microsoft.SharePoint.Client.Utilities.Utility.SendEmail(clientContext, properties);

            clientContext.ExecuteQuery(); 

But how can I send an attachment together with the email?

3 Answers 3

2

This is not a direct answer to the question, I am describing how we have solved this issue.

Change your app to provider hosted so that you can handle remove event receivers (RERs) (other parts remain the same including your current pages (if any) of auto-hosted app). To send the mail, create an item in one list with information needed to prepare mail content. Configure an RER on this list on item creation and handle it in provider hosted component and there use a local SMTP server or some other mechanism to send mail. Use CSOM to get whatever data/attachments you need to send in the mail.

We are using Azure for provider hosted component and use SendGrid Azure App to send mail.

1
  • I am also using SendGrid. But not able to get attachment say list item attachment into attachment property. Any thought on this. Commented Jun 9, 2016 at 15:47
0

Depending on your needs, what you can do is add a Visual Studio Workflow to you App project and set it up to send e-mails. If the attachments you want to send out are located on the SharePoint site, a link to the document is more preferred than actually sending the document itself.

Include sp.workflowservices.js in your App and use it to retrieve the Workflow instance, populate it with info, and start it.

-1

Alex,

SPUtility.SendEmail() with attachment (.ics files)

As the above suggests:

There is no possibility to send Attachments using this method. But you can use of SPAdministrationWebApplication to get the SMTP server details.

I'm not sure if SPAdministrationWebApplication is accessible in client object model.. Give it a try.. otherwise you might need to hard-code the email server address..

3
  • 1
    Thank you. The provided code is the one I use for my on-premise Version. Unfortunately SPAdministrationWebApplication is not available in CSOM. Do you know another way to figure out the outgoing server?
    – AdelPoint
    Commented Apr 28, 2014 at 8:21
  • 2
    The question is asking specifically for CSOM code - this answer is incorrect given this context. Commented Sep 18, 2014 at 14:15
  • As I mentioned in the answer, I wasn't sure if SPAdministrationWebApplication was accessible through CSOM.. So yes, it is incorrect in the given context.. But I would love if you could provide correct answer :) Commented Sep 18, 2014 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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