Attached and not inline email forwarding using EWS JavaScript API - javascript

I would like to kindly ask for some support on forwarding an email as attachment and not inline using EWS JavaScript API.
Even though I am a complete newbie in this area, I did not want to post a question here before reading as much as I could on the topic. I have studied all the documentation I could get my hands on, from msdn, github samples, most of the questions here on Stackoverflow and up to dev.oulook documentation like:
https://dev.outlook.com/Samples/Addins
https://dev.outlook.com/reference/add-ins/
etc. and I could not find an answer to how to forward the current email selected from inbox as attachment and not inline (to a predefined email address).
What I tried:
- obtain the ItemId of the email
- obtain the ChangeKey attribute for it
- with these values try to forward the email in 2 ways:
1) create an email in drafts and try to update it by adding the selected email as attachment
2) Create a new email and add as attachment the email selected from inbox
option 1) did not work and I noticed the attachment operations are all for composing emails and not draft emails (strange one I guess .. but not my main concern)
option 2) with this sample code:
var soapToForwardItem = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <soap:Header>' +
' <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
' </soap:Header>' +
' <soap:Body>' +
' <m:CreateItem MessageDisposition="SendAndSaveCopy">' +
' <m:Items>' +
' <t:ForwardItem>' +
' <t:ToRecipients>' + addressesSoap + '</t:ToRecipients>' +
' <t:ReferenceItemId Id="' + item_id + '" ChangeKey="' + changeKey + '" />' +
' <t:NewBodyContent BodyType="Text">' + comment + '</t:NewBodyContent>' +
' </t:ForwardItem>' +
' </m:Items>' +
' </m:CreateItem>' +
' </soap:Body>' +
'</soap:Envelope>';
had unfortunately the result: a new email with the old one inline and not as attachment (I am interested to preserve the email header of the attached email for later access).
I see there are examples where "inline" can be set to false for file attachments but not for item attachment.
Any constructive input or working code snippet would be highly appreciated.
Thank you!

Related

The attached email appears in compose mode when open in desktop Outlook

I attached an email message to a new message before sending it. But, the received attachment is editable on Outlook Desktop and is not on Outlook web. It means that when I try to open the attachment, it appears in compose mode in Outlook desktop. I used createItem to create and send the message, and ItemAttachment to put the attachment. I don't understand why it works on the web and not on the desktop.
Here is the part of code which make the attachment:
var soap = '<m:CreateItem MessageDisposition="SendAndSaveCopy">'+
' <m:Items>' +
' <t:Message>' +
' <t:Subject>' + subject + '</t:Subject>' +
' <t:Body BodyType="HTML">' + body + '</t:Body>' +
' <t:Attachments>' +
' <t:ItemAttachment>' +
' <t:Name>' + attachmentName + '</t:Name>' +
' <t:IsInline>false</t:IsInline>' +
' <t:Message>' +
' <t:MimeContent CharacterSet="UTF-8">' + attachmentMime + '</t:MimeContent>' +
' </t:Message>' +
' </t:ItemAttachment>' +
' </t:Attachments>' +
' <t:ToRecipients><t:Mailbox><t:EmailAddress>' + to + '</t:EmailAddress></t:Mailbox></t:ToRecipients>' +
' </t:Message>' +
' </m:Items>' +
'</m:CreateItem>';
Thank you.
You need to set the PR_MessageFlags extended property https://msdn.microsoft.com/en-us/library/ee160304(v=exchg.80).aspx on the attachment to make it appear sent eg
<t:Message>
<t:ItemClass>IPM.Note</t:ItemClass>
<t:Subject>subject</t:Subject>
<t:Body BodyType="HTML">body</t:Body>
<t:IsRead>false</t:IsRead>
<t:ExtendedProperty>
<t:ExtendedFieldURI PropertyTag="3591" PropertyType="Integer" />
<t:Value>1</t:Value>
</t:ExtendedProperty>
</t:Message>

How to make a line break using node.js and express-messages (\n isn't working)?

I'm using node.js with exppres and I'm trying to send a flash message from the server with 'express-messages'. Everything is working well but I don't know how to send a flash message with line breaking. I was trying to put \n and \r\n and the end of the line but nothing happened.
This is the party of my code:
req.flash('success', 'Yes !\n\n' +
'Your strength has increased by ' + newStrength + '.\n\n' +
'Your tolerance has increased by ' + newTolerance + '.\n\n' +
'Your charisma has increased by ' + newCharisma + '.\n\n' +
'Your intelligence has increased by ' + newIntelligence + '.\n\n' +
'You have gained ' + newCash + '$\n\n');
The response that I get is in one line and I really couldn't find the answer anywhere.

JS hide email function not working

I took the code below from a wider document, and tried to include it between 2 script tags, but for some reason it's not working (nothing happens).
Do I need to add some document ready syntax or something like this?
Thanks,
<script>
function sendAnnotatedMailTo(name, company, domain, subject, body) {
locationstring = 'mai' + 'lto:' + name + '#' + company + '.' + domain + "?subject=" + escape(subject) + "&body=" + escape(body);
window.location.replace(locationstring);
}
</script>
You only defined a function but didn't call it.
You have to call your function like this:
Send mail
This will open your mail client and prepare an email to name#democompany.domain.tld with the subject "Subject of mail" and the bodytext "Body of mail".
Btw: You shouldn't use the deprecated JS function "escape" anymore. Use encodeURI instead:
<script>
function sendAnnotatedMailTo(name, company, domain, subject, body) {
locationstring = 'mai' + 'lto:' + name + '#' + company + '.' + domain + "?subject=" + encodeURI(subject) + "&body=" + encodeURI(body);
window.location.replace(locationstring);
}
</script>

Sorry we could not fetch the image

I am facing one issue "Sorry we could not fetch the image" when I am clicking on pin it button:
below is the parameters I am passing
I am not getting what the this is missing :
1) ?url=
2) &media=
3) &description
This is the link which is creating in dailogbox :
http://www.pinterest.com/pin/create/button/?url=https://www.elivatefitness.com/lifestrength-ion-wristbands&media=https://www.elivatefitness.com/medias/LFE102-PureSeriesBlackGray.jpg-Default-WorkingFormat-479Wx479H?context=bWFzdGVyfHJvb3R8MTUxOTV8aW1hZ2UvanBlZ3xoNTUvaDFhLzg3OTk2MTg2NjI0MzAuanBnfDViZmIwMzM4ZTQ0NGQyYjQ1NWY2YmJkZTAxMjdjYjhmNjA3ZDk3ZDUwYTI2M2FmNzA1YjBlMTQyNDAyNzI1MTE&description=Combining%20comfort%20and%20improved%20performance%20the%20LifeStrength%20Ion%20Wellness%20Wristbands%20play%20an%20important%20part%20in%20boosting%20energy%20and%20fighting%20the%20negative%20effects%20of%20the%20environment%20around%20us%20to%20bring%20better%20health,%20relieve%20painful%20joints%20and%20encourage%20a%20deeper%20and%20more%20restful%20sleep.%20LifeStrength%20Ion%20Wellness%20Wristbands%20uses%20a%20proven%20method%20that%20combines%207%20natural%20minerals%20and%20gemstones%20into%20a%20slim%20Far-Infared%20infused%20silicon%20wristband%20you%20can%20wear%2024%20hours%20a%20day,%207%20days%20a%20week.%20Together%20the%20powerful%20mixture%20creates%20a%20unique%20band%20that%20emits%20more%20health-producing%20negative%20ions%20into%20your%20environment%20which%20in%20turn%20increases%20the%20flow%20of%20oxygen%20to%20the%20brain%20resulting%20in%20greater%20energy,%20alertness%20and%20an%20overall%20feeling%20of%20well-being.
Please help me out.
function pinIt()
{
var mediaURL = location.protocol + "//" + location.host
+ '${imgURL}' + "&description=" + "${description}";
window.open("//pinterest.com/pin/create/button/?url="+ document.URL + "&media=" + mediaURL,"",'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
}

xmlhttprequest POST method in rails

In the web, I'm building local file drag and drop upload to the server with the ruby on rails, dragging and drop a file working fine, but how to get the dragged file content in the controller with the drop event? I'm getting the file with event.datatransfer, send file through Javascript with XMLHttpRequest.
function handleDrop(event)
{
preventDef(event)
var dt = event.dataTransfer;
var files = dt.files;
for(var i = 0; i < files.length;i++)
{
http_request = new XMLHttpRequest();
var boundaryString = 'the_boundery--';
var boundary = '--' + boundaryString;
var requestbody = boundary + '\n'
+ 'Content-Disposition: form-data; name="thefilename"' + '\n'
+ '\n'
+ files[i].fileName + '\n'
+ '\n'
+ boundary + '\n'
+ 'Content-Disposition: form-data; name="thefile"; filename="'
+ files[i].fileName + '"' + '\n'
+ 'Content-Type: application/octet-stream' + '\n'
+ '\n'+files[i].path
+'\n'+ files[i].getAsBinary()
+ '\n'
+ boundary;
var preview = document.getElementById("preview");
preview.src = files[i].getAsDataURL();
var queryString="";
queryString="filename="+files[i].fileName+'&'+"file_to_upload=="+files[i].getAsBinary();
var actionUrl="/shortening/dr";
http_request.open('POST',actionUrl,true);
http_request.setRequestHeader("Content-type", "multipart/form-data; \
boundary=\"" + boundaryString + "\"");
http_request.setRequestHeader("Connection", "close");
http_request.setRequestHeader("Content-length", requestbody.length);
http_request.sendAsBinary(requestbody);
}
}
using this script calling the url and send the file through sendAsBinary method
Post method not calling the controller with the respective action
How to get the requestbody in the controller ?
Any idea?
First off, use some kind of javascript library to do AJAX and pretty much everything else. I'd suggest jQuery (http://jquery.com/)
Unfortunatelly no browser supports file uploads through XmlHttpRequest.
Read sometime ago something about Firefox supporting it, but that would be restricting and I'm not even sure that really works.
You could make an iframe and with the drop event, set the file field inside the iframe and then submit the iframe.

Categories