Apps Script is adding line breaks to email bodies - email

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

Related

Include quoted original message in mailto link body

I'm generating mailto links in support emails to make it easier to reply to customers directly from within Gmail. A typical mailto link might look like this:
mailto:customer#example.com?subject=Re%3A%20Feedback%20%20%20%5B1620394320%5D&body=%0A%0A%3E%20Original%20message%20from%20customer%40example.com%2C%202021-05-07%3A%0A%3E%20Customer%20message%20here
This works, except the original message is interpreted literally, even though the lines start with > (which I had expected to be interpreted as a quote of a previous message).
So the reply email would literally look like this for the customer:
> Original message from customer#example.com, 2021-05-07:
> Customer message here
What I want is for the lines starting with > to be treated as a quote of the original message, just like when replying to an email from any email client.
Is it possible to make Gmail do this with a body included in a mailto link?

How Unsend.it works?

I was a little bit surprised to see Unsend.it this morning.
How is it possible to unsend or edit a sent email ?
I would like to know technical details of how this works.
Is it possible for us to achieve this through programming ? If possible can anyone present me some code sample ?
They don't actually "un-send" the email. How it works is that the text content of the email is transposed into an image file and the text is removed from the email and replaced with the dynamic image file that contains the transposed text. So it looks like a text email, but is actually an image of the text of your email.
The image is remotely loaded from their servers so if you want to "un-send" the email, they change the image and remove the original text. The email itself remains in the recipients Inboxes', its now just a blank email that has been "un-sent".
Update 2019:
The email is not actually sent, instead they just wait for a cancellation period (which is configurable), to actually send it. So until this time passes, the email is actually sent. So if you click cancel within the timeframe, the email is never sent.

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

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.

Emails sent through joomla go to SPAM folder

I am using the latest Joomla build for my website.
Allso we use a DNS record for having the mail delivered to our own server instead of the server on which the website is hosted.
I have used several contact form components, but every sent mail goes to my SPAM folder.
After searching hours on the web (and getting linked to this site frequently) i decided to make a new post.
It does not matter if i use the standard joomla forms, or any component.
Whenever a user fills in a form on my website, the email gets sent. The user receives a copy of its message, and i receive the message of the user. However, this message gets thrown in the spam folder, as phishing.
The sender of the mail always is: username#nameserver.i3d.net; namens; websitename
What do i have to change/enable/disable for this to work?
Thanks in advance.
Patrick.
(Sorry, I'm new to Joomla, but it uses PHP, so this may apply. Also this answer got a little long...)
It might be an issue with the email headers. A lot of email clients will automatically spam-box all mail where the address in the From: header doesn't match the envelope sender. As an analogy, you might not trust a snail-mail letter signed "Your Rich Uncle", mailed in an envelope with a Nigerian return address. Also if your envelope sender has a different domain than the one the email is actually sent from, that's another quick ticket to the junk bin. For more info about Gmail's message blocking policies (and general good practices), you can try this help page.
Here's some basic PHP email-sending code:
$to = $userEmailAddress;
$subj = $emailSubject;
$mesg = $emailMessage;
$headers = implode("\r\n",array(
"MIME-Version: 1.0"
,"Content-type: text/html;charset=iso-8859-1"
,"From: WEB_ADMIN_NICE_NAME <WEB_ADMIN#YOURSERVER.COM>" // *** 'From:' header
));
$from = "-fWEB_ADMIN#YOURSERVER.COM"; // *** envelope sender
if(!mail($to, $subj, $text, $headers, $from)){
//Some error handling...
}
On the first line I commented, you'll want to replace WEB_ADMIN_NICE_NAME with the name you want the email recipient to see (e.g. "Bill Gates"), and on both lines, replace WEB_ADMIN#YOURSERVER.COM with the actual return address (e.g. "da_boss#microsoft.com"). Note: whatever address you choose for the return address is where users' replies will be sent.
To reiterate, make sure both lines have the same return address (though the nice name can be anything you like), and make sure that the actual server sending the mail is in fact located at YOURSERVER.COM.
Lastly, I'm not sure where Joomla does its mailing, but if you're totally lost, you can try grepping with -lr for 'mail[[:space:]]*('.
there are several reasons that could make your email look suspicious to spam filters; to find out which head on to:
http://www.mail-tester.com
grab the email address and send an email from your website to it.
Then go back to the page and it will tell you what's wrong.
btw I'm struggling with the same issue,my problem being that on Joomla 2.5.9 apparently when you send html emails, a text-only copy is not added to the message, which is considered "spammish behaviour"
The problem is the i3d.net email address. My personal experience is that their network (31.204.154.0 - 31.204.155.255) is a significant source of spam and they do not action abuse reports. I suggest changing your hosting company.

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.