PHPmailer and boundary headers - phpmailer

Is it possible to add/update boundary headers via PHPmailer for the code
$mail->addStringAttachment($test, 'test.txt', 'quoted-printable');
I need to add/update
--b1_KyZbvbrSl55hdWoQf7uUOwdfF2oGjqnCyP6rqNmlA
Content-Type: text/plain; name="test.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename=test.txt
to looks like
--b1_KyZbvbrSl55hdWoQf7uUOwdfF2oGjqnCyP6rqNmlA
Content-Type: text/plain; name="test.txt"; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename=test.txt
Content-ID: 20cca107-2625-49ce-9357-95254a59147f#127.0.0.1
so for the Content-Type header was added charset parameter and then added new header Content-ID
Any tips on that?

After further investigation it came up that
The addStringEmbeddedImage method lets you set a cid for the
attachment which will set that header for you. You can ignore the
"image" in the method name - it doesn't care what type of content you
attach really.
So in my case it will be
$mail->addStringEmbeddedImage(file_get_contents($file_name, FILE_USE_INCLUDE_PATH), $uuid, $file_name, 'base64', '', 'attachment');
Regarding adding charset parameter to the Content-Type boundary header
quoted-printable transfer encoding is ASCII 7bit safe, so the default
will work fine and it doesn't need an extra charset clause.

For transfer-encoding and charset
$mail->Encoding = 'quoted-printable';
$mail->CharSet = 'UTF-8';
For content-id check addEmbeddedImage method or try adding directly the header like this:
$mail->addCustomHeader('Content-ID', '20cca107-2625-49ce-9357-95254a59147f#127.0.0.1');

Related

Send hyperlinks in email body using AWS SES in Node.js

I am using the AWS.SES (simple email service) kit in my Node.js Lambda function.
I can send emails just fine, but if I try to include a simple hyperlink in the email, it displays just plain text instead of a clickable hyperlink.
This is the code I'm using to send the email.
function sendVerificationEmail(userinfo, vKey, after) {
var params = {
Destination: {
ToAddresses: [userinfo.email]
},
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: "<html><body>Hey " + userinfo.name + ", <a href='https://s3.amazonaws.com/xxxx/xxxx.html?v=" + vKey + "'>Click here to validate this email address.</a></body></html>"
},
Text: {
Charset: "UTF-8",
Data: "Hey " + userinfo.name + ",\n\nOpen this link in your web browser to validate this email address:\nhttps://s3.amazonaws.com/xxxx/xxxx.html?v=" + vKey
}
},
Subject: { Data: "Scheduler - Verify Your Email Address" }
},
Source: "xxxx#gmail.com"
};
ses.sendEmail(params, function(err, data) {
after(err, data);
});
}
As you can see in the HTML, I have included an <a> tag. However, The link is displayed as unclickable plaintext in the email.
Edit: Gmail's "Show Original" feature displays the following:
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Hey TestName,
Open this link in your web browser to validate this email address:
https://s3.amazonaws.com/xxxx/xxxx.html?v=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
---------------------------------------------------
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<html><body>Hey TestName, <a href='https://s3.amazonaws.com/xxxx/xxxx.html?v=xxxxxxxxxxxxx'>Click here to validate this email address.</a></body></html>
If you observe the raw email contents you will observe that it misses the = sign between in href=<link>. This is because the '=' symbol is used as a line break in the smtp protocol messages(I think).
Anyways, the way to fix this is to add the unicode for the '=' symbol which is U+003D
Try this:-
${text}
The =3D is interpreted as the = symbol and the content encoding is done correctly.

trying to reply to an existing email with gmail API

I'm trying to reply to an existing email with Gmail API:
Since I don't have in the existing mail that i want to reply to the headers of References, In-Reply-To then i'm using the Message-ID instead to fill what I'm sending
DB5PR03MB1206D3A24F124BDF43A5C6E683D60#DB5PR03MB1206.eurprd03.prod.outlook.com is the Message-ID header of existing mail.
I've created the following RFC-802:
Content-Type: text/plain; charset="UTF-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
References: <DB5PR03MB1206D3A24F124BDF43A5C6E683D60#DB5PR03MB1206.eurprd03.prod.outlook.com>
In-Reply-To: <DB5PR03MB1206D3A24F124BDF43A5C6E683D60#DB5PR03MB1206.eurprd03.prod.outlook.com>
Subject: sdfasdf
to: "xxx#gmail.com" <aaa#gmail.com>,<xxxx#xxx.me>
from: aaa#gmail.com
aaaaaaaaa
then i get an error:
that an error occured the message wasn't sent.
I read this post but this post presumes that always i have the following two headers:
References
In-Reply-To
Remove References and set In-Reply-To : Message-ID
Content-Type: text/plain; charset="UTF-8" <br />
MIME-Version: 1.0<br />
Content-Transfer-Encoding: 7bit<br />
In-Reply-To: Message-ID<br />
Subject: sdfasdf<br />
to: "xxx#gmail.com" <aaa#gmail.com>,<xxxx#xxx.me><br />
from: aaa#gmail.com<br />
aaaaaaaaa

Soap UI Post Payload Groovy variable substitution

Soap UI (Free version)
I have a test case that is a POST that accepts XML as the payload. I wrote a groovy script in the test case that will calculate the readingDate field.
Groovy Script:
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.TimeZone
Calendar currentTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
dateFormat.setTimeZone(currentTime.getTimeZone())
String readingDate = dateFormat.format(currentTime.getTime())
context.setProperty("readingDate", readingDate)
XML Payload:
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns="http://www.foo.com/data">
<foobar foobarId="1553310377_20">
<foobarReading>
<readingDate>${readingDate}</readingDate>
<readingValue>451.045</readingValue>
</foobarReading>
</foobar>
</foo>
Request Shown:
POST http://foo:8080/WebServices/rest/data HTTP/1.1
Connection: close
Accept-Encoding: gzip,deflate
Content-Type: application/xml
Authorization: Basic TlJDYW46TlJDYW4=
Content-Length: 301
Host: foo:8080
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns="http://www.foo.com/data">
<foobar foobarId="1553310377_20">
<foobarReading>
<!-- Should not be empty it should show the current time -->
<readingDate></readingDate>
<readingValue>451.045</readingValue>
</foobarReading>
</foobar>
</foo>
You can achieve that in two ways:
Provided you have the Groovy Script test step invoked before the REST Call. Follow the below modifications to the Groovy Script.
//Instead of setting the property to context
//context.setProperty("readingDate", readingDate)
//Approach 1:
//Set it as a global property for SoapUI
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue('readingDate', readingDate)
//Approach 2:
//Or if you do not want to set it globally and ruin other tests
//Set it as a project (SoapUI Project) property.
//testRunner.testCase.testSuite.project.setPropertyValue('readingDate', readingDate)
In the former case the xml would look like
<readingDate>${readingDate}</readingDate>
In the later case, the property should be a Project property, so
<readingDate>${#Project#readingDate}</readingDate>

Node.js - generate multipart/form-data

Is there a Node.js library for generating multipart/form-data content in the following form?
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="to"
destination#email.com
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="from"
recipient#email.com
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="subject"
subject line
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="text"
This content does not matter.
------------------------------7a9cd2dc11c1--
fermata looks like it might be what you're looking for. From the github page:
fermata.json("http://example.com/some/action").post({
'Content-Type':"multipart/form-data"
}, {
fileField: form.input.file || {data:nodeBuffer, name:"", type:""}
}, callback)
request supports multipart/form-data or if you're just looking to create the content body, try form-data
I know this is old but I recently needed to generate a form's multipart/form-data body string and came across this thread.
I was unable to find any modules out there that did this in a simple way so I made my own module: https://github.com/kodie/form-data-body
You can use it like so:
const formDataBody = require('form-data-body')
// Specify form fields
const fields = {
name: 'My test post',
description: 'This is just a test post',
items: ['First Item', 'Second Item'],
// Files should be an object with the name, type, and data set to strings
image: {
name: 'hello.jpg',
type: 'image/jpeg',
data: binaryImageData
}
}
const boundary = formDataBody.generateBoundary()
const header = {
'Content-Type': `multipart/form-data; boundary=${boundary}`
}
const body = formDataBody(fields, boundary)
Example Output:
----------------------------071517909670537006900435
Content-Disposition: form-data; name="name"
My test post
----------------------------071517909670537006900435
Content-Disposition: form-data; name="description"
This is just a test post
----------------------------071517909670537006900435
Content-Disposition: form-data; name="items[]"
First Item
----------------------------071517909670537006900435
Content-Disposition: form-data; name="items[]"
Second Item
----------------------------071517909670537006900435
Content-Disposition: form-data; name="image"; filename="hello.jpg"
Content-Type: image/jpeg
[BINARY IMAGE DATA]
----------------------------071517909670537006900435--

GMail doesn't mark up email html (sending via PHP)

I am trying to send a html email via mail(), however gmail just displays the email as plain text, no mark up, eg:
mail("blah#blah.com", "<i>Italic Text</i>");
just appears as
<i>Italic Text</i>
Any ideas?
Have you set your email headers?
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
If yes, do any other email clients have the same problem? Or is it just Gmail?
Try it with css, the i tag is deprecated, not sure if that is causing it...
<span style='font-style:italic;'>Italic Text</span>
Or you could try using the em tag:
<em>Italic Text</em>.

Resources