Sample to submit email with an attachment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Loads the form items to attach to events | |
function loadForm() { | |
$("#forward-button").click(function () { | |
getCurrentMessage(); | |
}); | |
} | |
// This function handles the click event of the sendNow button. | |
// It retrieves the current mail item, so that we can get its itemId property | |
// ans also get the MIME content | |
// It also retrieves the mailbox, so that we can make an EWS request | |
// to get more properties of the item. | |
function getCurrentMessage() { | |
var item = Office.context.mailbox.item; | |
itemId = item.itemId; | |
mailbox = Office.context.mailbox; | |
try{ | |
easyEws.getMailItemMimeContent(itemId, sendMessageCallback, showErrorCallback); | |
} catch (error) { | |
showNotification("Unspecified error.", err.Message); | |
} | |
} | |
// This function is the callback for the getMailItemMimeContent method | |
// in the getCurrentMessage function. | |
// In brief, it first checks for an error repsonse, but if all is OK | |
// t:ItemId element. | |
// Recieves: mail message content as a Base64 MIME string | |
function sendMessageCallback(content) { | |
var toAddress = "bob@contoso.com"; | |
var comment = $("#forward-comment").val(); | |
if (comment == null || comment == '') { | |
comment = "[user provided no comment]"; | |
} | |
try{ | |
easyEws.sendPlainTextEmailWithAttachment("Message with Item Attachment", | |
comment, | |
toAddress, | |
"Email Attachment", | |
content, | |
successCallback, | |
showErrorCallback); | |
} | |
catch (error) { | |
showNotification("Unspecified error.", err.Message); | |
} | |
} | |
// This function is the callback for the easyEws sendPlainTextEmailWithAttachment | |
// Recieves: a message that the result was successful. | |
function successCallback(result) { | |
showNotification("Success", result); | |
} | |
// This function will display errors that occur | |
// we use this as a callback for errors in easyEws | |
function showErrorCallback(error) { | |
showNotification("Error", error);// .error.message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment