Win8/WinRT - How to add line breaks in email body - email

In my Windows 8 Store app, I have a Send Email button on a page and users are able to click it and send us an email for some general enquiries.
I need to pre-load some text in the email body but I can't seem to add line breaks to it. I tried Environment.NewLine and "\r\n". None of them works.
var mailto = new Uri("mailto:?to=james.jones#example.com&subject=Hello world&body=Hi," + Environment.NewLine + "Can you please ...");
await Windows.System.Launcher.LaunchUriAsync(mailto);
When I run it, I get "Hi,Can you please...". The line break is omitted.

Try using "%0d%0a" as your line break, as in
"Hi,%0d%0aCan you please..."
That's a URL-encoded ASCII CR/LF sequence. That works for me for the built-in Mail app but you don't have any particular guarantee that it would work for any arbitrary mail app that the user might install in the future.

The reason it doesn't work is because you're launching a Uri, Uris require that their contents be UrlEncoded / UrlEncodable. In the case of Environment.Newline etc you'd get an invalid Uri.
You can counter this by UrlEncoding the Environment Newline like this:
System.Net.WebUtility.UrlEncode(Environment.NewLine)

You maybe should consider using a Share Contract to share your content to your Mail App. Benefits: Users using your software can share it to other Apps, not only Email.

Related

Apps Script is adding line breaks to email bodies

I am generating emails with Google Apps Script and the emails are being sent with line breaks in weird places.
Here is my code
function sendEmail(){
var name = "MyName"
var body = name + " has issued a challenge. You already have a match currently scheduled so you have the option to decline. Reply to this email with the word 'ACCEPT' or 'DECLINE' in the subject." +
"\n\nNOTE: If you do not respond to this email you will automatically accept the challenge and be responsible for scheduling the match within two weeks or suffer a forfeit."
GmailApp.sendEmail("MyEmail#gmail.com", "You've been challenged!", body)
}
You'll notice that it is also putting the text of the first section of the body in a purple color. I also don't know why this is happening but my priority is to stop the line breaks from being put where they shouldn't be.
Google 'Stacks' emails. Say for example I send you an email. Then you reply and I reply again. It stacks them all into one line in your inbox.
Any identical paragraphs in the emails are made purple. Only you see the purple.
If you delete all of the emails out of your inbox and test again, you should notice it in black.
Also, you have code to create two new lines. '\n' x2. You're essentially creating a new paragraph, do you just want a new line to begin instead? If so delete 1x '\n'. Sorry if I'm not understanding your issue.
If you were to insert the body as html and use paragraph tags you would likely be able to achieve the results you are pursuing.
I am on mobile and don't know how to get resource links to prove the above sorry.
Edit: I would make the following change:
body = name + " has issued a challenge. You already have a match currently scheduled so you have the option to decline. Reply to this email with the word 'ACCEPT' or 'DECLINE' in the subject." + "\n\n" + "NOTE: If you do not respond to this email you will automatically accept the challenge and be responsible for scheduling the match within two weeks or suffer a forfeit."
Your code is including the body as plain text so it is automatically cropped at certain line length. Below some questions about the same "problem"
Gmail API - plaintext word wrapping
Why isn't Gmail using quoted-printable encoding?
If you want to have more control about how the message content looks on Gmail, besides sending the content as plain text sent it as HTML. For doing this use
sendemail(recipient,subject,body,options)
Related questions about using the above method:
Sending an email in HTML and plain with a Gmail Apps Script

Links have random characters prepended in email

I am using the current link in my email.
*|baseUrl|*/verifyEmail?token=*|token|*
This however causes one or two people to get strange links from the email and get not found, usually based on some random email providers. E.g. - if I use a 10 minute mail (10minutemail.com), I get the following:
https://10minutemail.com/10MinuteMail/www.mywebsite.com/verifyEmail?token=b32fee82da59e7b4085269faca35ec7025122876
Correct link: www.mywebsite.com/verifyEmail?token=b32fee82da59e7b4085269faca35ec7025122876
Assuming this is due to baseUrl? Am I doing something fundamentally wrong when setting up my email link?
You need to include http:// or https:// with your baseUrl. Otherwise the email client may prepend a default base address instead of 'just' the missing protocol, especially if it is a webmail client.

Is it possible to hack mailto?

Sorry about the provocative subject but I could not think of a better word than "hack" to describe what I would like to do!
On my site, I provide links to other sites and on request by the user, display a page from the site in a frame or pop up window. Frequently these displayed pages have a mailto-tag.
I have found it extremely annoying that clicking the mailto link starts off my outlook which I no longer use but retain it as an installed program on my machine.
What I would like to do is:
1) Pick up the subject and email address part of the mailto tag.
2) Pop up an HTML form where the email address and the subject is prefilled.
3) Send the email message through my site's mailserver instead of through outlook or any other mail client.
Is there a way to do this?
Thank you in advance - and once again apologies for the provocative subject line!
Cheers!
Uttam
Try it using javascript.
With using a framework like jQuery its easy so find such tags inside a frame or popup window.
You can try it by something like this:
var allATags = $('myFrameId').find('a');
$(allATags).each(function(index, element){
var href = $(element).attr('href');
//here you shall try to find out if there a mailto Link or a normal link, e.g. using regular expression or indexOf()
[...]
if (isMailToLink){
//split the href String at the signs '&' with which the subject, mail, etc is splitted and removing the mailto, putting all in own variables
[...]
$(element).attr('href', 'javascript:void(0);');
$(element).click(function(){
showMyMailForm(toMail, mailSubject, mailBody);
});
}
});
On opening a document in a frame or a popup wait for the document being loaded and then run your code to replace all existing mailto-links on that document with your mailform-mailer.
The code is just a way trying to inspire, no working code.
Users can set their default email client, here are a couple of links that may be helpful:
Firefox
Chrome
Internet Explorer
Of course this is controlled by the user, so it will help you personally, but not force others to use a specific program.
You could easily pass url parameters onto your contact landing page/email form instead of a mailto link, something like a href="http://landingpage.com/index.php?email=you#you.com&subject=hello" could be used to pre-fill generic contact/email form fields.

Sharepoint: use mailto command to send subject and body

I am developing in SharePoint and I would like to prepare a mailto command but I would like to send two values to the email and not just one. Normally in html the command works
Email
But in SharePoint I seem to only be able to send the first section after the email#here.com?. Depending on what I position first, I sometimes get the #Body field to go through or the #Title to go through. It appears that for some reason the "&" isn't accepted. I also tried %26 in the place of & with no result.
What is the best method to get both (body and subject) to go through to the mail-client?
Thank you in advance for your time, any guidance will be greatly appeciated

Embed indentifier within an Email

I am trying to embed an ID into an email so that when a recipient replies to an email that my system sends out, my system can pick it up and match the two together.
I have tried appending a custom header, however this is stripped out when the user replies.
I have tried embedding an HTML comment within the email, but outlook does not seem to keep comments when a reply email is created.
Worst case scenario, I can manually try and match the sent and received emails by time span or have a visible tag within the message body.
Does anyone know of a more elegant solution?
Thanks in advance
Email messages already contain such an identifiers, called Message-ID. And there's even a way to send which message you're replying to by sending that ID in a header called In-Reply-To. That's done by pretty much all email clients, that's how they usually do their threading.
It's defined in RFC 822 (yep that's pretty old) and probably re-defined and refined in more modern versions of that.
I have seen a method that includes a one byte image with a unique name that's linked to the user. When they view the email and download the images, your HTTP server will record a hit for that unique image. Of course the user needs to display images, but you can include a message in the body asking them to display the images. We actually include content in an image so they need to show images.
If your incoming e-mail can handle +foo or -foo suffixes, use that.
Many e-mail systems can route user+foo#example.com or user-foo#example.com
to user#example.com. You can replace foo with some kind of identifier.
Several mailing list servers use this for tracking bounces.
While I can't say for certain, my investigation in that sort of matter some time ago yielded the following "conclusion":
Headers are transformed a lot
Message bodies are transformed a lot
This is partly because, I suspect, of:
Need to protect users from malicious intentions
Need to perform "targeted marketing"
I have seen "unique codes" flying around in clear text in the email body but I would suggest having a unique identifier embedded in the return address instead.
The usual approach is to place the id in the subject line and/or somewhere visible in the message text and informing the recipient that he should not modify the subject or quote the original mail when responding.