2

I'm required to create a form which when submitted sends an approval/rejection email.

How would I go about doing this ?

1

4 Answers 4

2

You can send an email using a SharePoint hosted app one of two ways:

You can simply use javascript to make a REST call to SP.Utilities:

function sendEmail() {

appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));
hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
var urlTemplate = appweburl + "/_api/SP.Utilities.Utility.SendEmail";
$.ajax({
    contentType: 'application/json',
    url: urlTemplate,
    type: "POST",
    data: JSON.stringify({
        'properties': {
            '__metadata': { 'type': 'SP.Utilities.EmailProperties' },
            'From': '[email protected]',
            'To': { 'results': ['[email protected]'] },
                'Body': 'Hello',
                'Subject':'remember'
            }
    }
  ),
    headers: {
        "Accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    success: function (data) {
        var result = data.d.results;
        var i = result.length;
    },
    error: function (err) {
        alert(JSON.stringify(err));
    }
});
}

Or you can create a site workflow, and then use the following JavaScript to start the workflow:

function initWorkflowSubScriptionService() {  
    _wss = wfManager.getWorkflowSubscriptionService();  
    context.load(_wss);  
    context.executeQueryAsync( 
    function (sender, args) {  
         subscription = _wss.getSubscription("f248e55e-495c-4c9b-b4de-618033d6be3b");  
         params = new Object();  
         params["argSubj"] = argSubj;  
         params["argBody"] = argBody;  
         params["argTOEmail"] = argTOEmail;  
         context.executeQueryAsync( function (sender, args) {  
             wfManager.getWorkflowInstanceService().startWorkflow(subscription, params);  
             context.executeQueryAsync( 
                 function (sender, args) { },  
                 function (sender, args) {  
                 console.log("Something went wrong in starting workflow: " + args.get_message() + '\n' + args.get_stackTrace());  
                 }  
             )  
         })  
    },  
    function (sender, args) {  
     console.log("Something went wrong in starting workflow: " + args.get_message() + '\n' + args.get_stackTrace());  
    });  
}  
0

The System.Net.Mail namespace works with on-premise Sandbox solutions but does not work with Office 365, so there is no way to send email from code. The "Send Email" activitiy in SharePoint Designer workflows in Office 365 does work, so yes, you can use workflow to send email.

To send email with infopath form you can check:

http://community.office365.com/en-us/f/148/t/225407.aspx

2
  • So is there no way to create a simple HTML based form and have it send any kind of email ? May 20, 2014 at 15:25
  • Unfortunatly the workflow it self wont suffice. We have a lot of paper based processes which are going to be made electronic via sharepoint. So i'm assuming there isn't anyway of having a form submit its input to email ? May 21, 2014 at 7:39
0

Does it have to be a custom form? You can use an approval workflow and create it in Sharepoint Designer. The template for the workflow is pre-defined and it's a very popular workflow so you will find plenty of tips and tutorials, eg.

http://office.microsoft.com/en-001/sharepoint-help/all-about-approval-workflows-HA102771433.aspx

You can customize the content of the email and you can set the workflow to start upon submitting an item to the SPO list. The item form can be customized as well.

0

To send e-mail after form submission you can create SharePoint Designer workflow, which will be started on item creation.

Out of the box workflow action for Office 365 works, but it can't send messages to external recipients as well as attachments.

You can try to use 3rd party workflow action Send e-mail with attachments from Workflow Actions Pack.

You can read my blog post to understand how to work with this workflow action. This post doesn't do exactly what you need, but you will get general understanding of how to use it.

Workflow Actions Pack is a paid but cheap enough solution developed by my team.

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.