Mail RFC embedded image using cid for text/plain - image

While I remember email messages could contain embedded images in HTML and plain text I noted today Outlook 2013 and Windows 10 Mail app does not display it.
Is this something the RFC standard has removed the "[cid:]" definition?
Below is the formatted mail:
(save as *.eml to display its content)
MIME-Version: 1.0
Date: Tue, 6 Feb 2018 10:12:53 +0100
From: Test User 2 <test.user2#lab.local>
Subject: TEst in plain text
Thread-Topic: TEst in plain text
To: Test User 1 <test.user1#lab.local>
Content-Type: multipart/mixed;
boundary="_60A9E784-DBBE-4378-9A84-01D36C2226AF_"
--_60A9E784-DBBE-4378-9A84-01D36C2226AF_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"
test
[cid:BBCLOGO#23AD2D600E]
--_60A9E784-DBBE-4378-9A84-01D36C2226AF_
Content-Type: image/jpg; name="23AD2D600EF4C69FF4D5479A8BB7FE73.jpg"
Content-ID: <BBCLOGO#23AD2D600E>
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="23AD2D600EF4C69FF4D5479A8BB7FE73.jpg"
/9j/4AAQSkZJRgABAgAAZABkAAD/2wBDAAIBAQEBAQIBAQIDAgECAwMCAgICAwMDAwMDAwMFAwQE
BAQDBQUFBgYGBQUHBwgIBwcKCgoKCgwMDAwMDAwMDAz/2wBDAQICAgQDBAcFBQcKCAcICgwMDAwM
DAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAAyADIDAREA
AhEBAxEB/8QAHAAAAgIDAQEAAAAAAAAAAAAAAAcFCAIEBgMJ/8QAOBAAAQIFAQYBBw0BAAAAAAAA
AQIDAAQFBhETBwgSITFRQTQ1QmFicYEUFiIyMzZDY3KEkZSh8P/EABoBAAIDAQEAAAAAAAAAAAAA
AAAFAgMEBgH/xAAnEQACAgECBQMFAAAAAAAAAAAAAQIRAwQxBRIhUYEyQcEiYZHw8f/aAAwDAQAC
EQMRAD8A+mmqvvHWUJw1V94KAk7YtG67zmzJWzJuTTqcaik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related Content-type"
To refer to an attachment by the value of its Content-ID (CID) MIME header field, it's as simple as:
<img src="cid:BBCLOGO#23AD2D600E">
Note that your body must be HTML, such as Content-Type: text/html; chaset="us-ascii", as indicated by RFC 2045 §5.
Outlook should do this automatically when you place images in your message body. If you need further help configuring that, there is probably a more appropriate Q&A site than (the programming-centric) Stack Overflow.

Related

Can Content-Disposition filename be used for text fields in multipart forms with Spring Webclient?

Working with the Service-Now API (for example) requires the request to provide the following:
POST /api/now/attachment/upload HTTP/1.1
Host: somehost.testenv.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MadHyZrFTrZu0gW
cache-control: no-cache
Content-Disposition: form-data; name="table_name"
some_table
Content-Disposition: form-data; name="table_sys_id"
82c9aca7kljasdfkljhasdfec8dfdb61d961920
Content-Disposition: form-data; name="uploadFile"; filename="undefined"
Content-Type: file
------WebKitFormBoundary7MA4YWxkTrZu0gW—
The above is generated from using Postman and providing form-data key value pairs.
However, based off the abstract of the RFC that defines Content-Disposition: https://www.rfc-editor.org/rfc/rfc2183.
Two values for this
header field are described in this memo; one for the ordinary linear
presentation of the body part, and another to facilitate the use of
mail to transfer files.
The Content-Disposition class used in Spring Webflux (https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/http/ContentDisposition.html) contains only an internal field for "filename" that is a string.
Is the ContentDisposition class in org.springframework.http missing a component as per RFC-2183 regarding a standard value (ordinary linear presentation of the body part)?
The HTTP request that is generated by the spring code automagically is as follows:
POST /api/now/attachment/upload HTTP/1.1
user-agent: ReactorNetty/0.7.9.RELEASE
transfer-encoding: chunked
host: somehost.testenv.com
accept: */*
accept-encoding: gzip
Content-Type: multipart/form-data;boundary=o-0JsSvUdGo98NDHJSWTwjvgzlRSXsmJ98-pWQ;charset=UTF-8
This is the source code that generates the above HTTP request:
MultipartBodyBuilder mbuilder = new MultipartBodyBuilder();
mbuilder.part("table_name", snConfig.getChangeRecordTableName());
mbuilder.part("table_sys_id", result.get(0).getSysId());
mbuilder.part("uploadFile", someFile);
return client.post()
.uri(snConfig.getEndpointAttachmentUpload())
.contentType(MediaType.MULTIPART_FORM_DATA)
.syncBody(mbuilder.build())
.retrieve()
.bodyToMono(AttachmentUploadResult.class);
It looks like the code is storing all of the MultipartBodyBuilder components into a single multipart/form-data, which is not the same format as the working HTTP Request.
However, even by manually providing the Content-Disposition headers, one can only create a name/value pair where the value is the "filename".
Is Content-Disposition missing functionality? Is this possible with WebClient?
Looks like this isn't supported within WebClient after digging on this for a long while.

How to read a value of Location from response header in jmeter?

I am getting below Header Response :-
HTTP/1.1 202 Accepted
Content-Length: 0
Location: https://localhost:111/api_path/916e0a93-552f-46fd-84c4-6cecac92209a
Server: Microsoft-IIS/10.0
X-SourceFiles: =?UTF-8?B?RDpcR2l0SHViXFJNTVxFZGdlUHJvdG90eXBlXEVkZ2VQcm90b3R5cGVcYXBpXHYxXFNubXBcR2V0VjFBc3luYw==?=
X-Powered-By: ASP.NET
Date: Thu, 30 May 2019 13:13:24 GMT
how can I use regular expression to capture the below value from Location ?
916e0a93-552f-46fd-84c4-6cecac92209a
I am not saving my response in file and i want a value of Location from Response Header
I tried below way but getting NOT FOUND as it is default, if i remove default then it will show null
Replace your regular expression with
Location: https:.+api_path\/(.*?)\n
Make sure you use Apply to Main sample only.

JMeter Multipart JSON Request Form Data

I am trying to construct a HTTP Request through JMeter that uses a multipart data body.
I have a HTTP Header Manager that has COntent-Type set to multipart/form-data; boundary=AaB03x. I selected 'Use multipart/form-data for POST'.
I then have a data body created as,
`-----------------------------AaB03x
Content-Type: application/json
Content-Disposition: form-data; name="part1"
{"jsonKey1": "JsonValue1" }
-----------------------------AaB03x
Content-Type: application/json
Content-Disposition: form-data; name="part2"
{
"jsonKey2": "JsonValue2"
}
-----------------------------AaB03x
Content-Type: application/octet-stream
Content-Disposition: form-data; name="part3"
File Content here!!!!
-----------------------------AaB03x`
When I run this, I see that the request doesnt send the body correctly, instead it just sends some random data as,
POST data:
--vKOghkU7riRQbaANmmGpMs7j9TxCTUp3S2T0vE--
And gives an error response of,
`{"errorMsg":"Unable read headers from MultipartStream.","messageCode":"UnableReadHeadersFromMultipartStream","httpStat us":"BAD_REQUEST","requestName":"RequestName"}`
My second question is:
the part3 of the request sends a file to upload. Can I pass the file path somehow?
Given you set your own boundary and build your request manually I believe you need to uncheck Use multipart/form-data for POST in the HTTP Request Sampler
If your file encoding isn't very "exotic" you can try using __FileToString() function just instead of File Content here!!!!.
Looking into RFC 7578, it seems you also need a trailing -- at the end of the last line
You should try sending your JSON data as parameters. Also put your file path in the section for that... And even some servers don't actually need MIME type explicitly declared, you can check yours with some online tool like this one.
Your HTTP Request could look smethnig like:

The safest way to add a header and a footer to an e-mail?

I am busy writing the last bit of an SMTP relay engine. Basically, people send mail to this SMTP address, it gets piped to files, analyzed, and then headers and footers are added to the body. My problem is, I'm not sure if my way of altering the mail will work for all cases. Basically, if I have this:
Return-path: <XXXX#YYYY>
Envelope-to: system-filter
Delivery-date: Thu, 25 Sep 2014 12:43:53 +0200
Received: from localhost ([127.0.0.1]:XXXX helo=XXXX.XXXX.com)
by XXXX.XXXX.com with XXXX(XXXX-XXXX-XXXX-XXXX:XXXX)
(Exim XXXX)
(envelope-from <XXXX#XXXX.XXXX>)
id XXXX-XXXX-67
for XXXX.XXXX#XXXX.com; Thu, 25 Sep 2014 12:43:52 +0200
Received: from XXXX.XXXX.XXXX.XXXX ([197.87.204.210]) by XXXX.XXXX.com
(Horde Framework) with HTTP; Thu, 25 Sep 2014 10:43:50 +0000
Date: Thu, 25 Sep 2014 10:43:50 +0000
Message-ID: <XXXX.Horde.XXXX#XXXX.XXXX.com>
From: XXXX#XXXX.XXXX
To: XXXX.XXXX#XXXX.com
Subject: This is the subject
User-Agent: Internet Messaging Program (IMP) H5 (XXXX)
Content-Type: text/plain; charset=UTF-8; format=flowed; DelSp=Yes
MIME-Version: 1.0
Content-Disposition: inline
X-OutGoing-Spam-Status: No, score=-2.9
And this is the message.
The idea was to either:
1. Just find the first blank line and put the header there, and then just append the footer to the end.
2. Use PHP Mime Mail Parser to alter the body
The problem with 1 is that I think there might be different formats coming in that don't follow the normal layout. The problem with 2 is, I'm limited to whatever the mail parser can parse.
So, what is the safest way to relay e-mails as I've desribed?
Just prepending or appending something to a message body will not work. It will not work because the message can by multipart (e.g. with attachments) or encoded (e.g. base64). PHP Mime Mail Parser seems to be able to handle these cases, but it doesn't have a method to save the modified message.
I would recommend using some email parsing library which can write messages, not just read. For example, Python standard library has email package which can do what you need. However, you would have to check if the message is multipart and if so add the header and the footer to the right part (i.e. to the actual content and not to an image or attachment). You will also need to check whether the message is plain text or HTML and have your header and footer formatted appropriately.

Sending an HTML email with an attachment

I have a question about net/smtp
For html emails you have to set this in the header of the email content-type: text/html . However, if you want to send an attachment you have to change it to content-type: multipart/mixed. Which would make the html email...not html anymore.
So the question is.. how do I accomplish both? HTML and attachment?
Thank you
Each attachment has its own MIME type
Each part of a multipart email has its own MIME type. So, while the email's content-type is "multipart/mixed", each attachment has its own MIME type (text, HTML, etc).
Here is an example multipart email from MIME and HTML in Email by Doug Steinwand:
To: whoever#someplace.com
Subject: MIME test
Content-type: multipart/mixed; boundary="theBoundaryString"
--theBoundaryString
Plain text message goes in this part. Notice that it
has a blank line before it starts, meaning that this
part has no additional headers.
--theBoundaryString
Content-Type: text/html
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Content-Base: "http://somewebsite.com/"
<body><font size=4>This</font> is a
<i>test</i>.
--theBoundaryString--
Here you can see that the text attachment has no explicit content type. When an attachment has no explicit content type, it is US ASCII TEXT. The HTML attachment has a content type of "text/html". There could be other attachments, each with their own MIME type.
Consider using the "mail" Gem
The mail gem makes sending and parsing multi-part emails very easy. It is stable, well maintained, and widely used.
This example from its README shows how to send a multi-part mail with a text part and an HTML part:
mail = Mail.deliver do
to 'nicolas#test.lindsaar.net.au'
from 'Mikel Lindsaar <mikel#test.lindsaar.net.au>'
subject 'First multipart email sent with Mail'
text_part do
body 'This is plain text'
end
html_part do
content_type 'text/html; charset=UTF-8'
body '<h1>This is HTML</h1>'
end
end

Resources