I am trying to create a multipart/signed mime email following the RFC1847 protocol.
This is how it is supposed to look (part of the signature is removed):
Content-Type: multipart/signed; protocol="application/pkcs7-signature"
micalg=sha1; boundary="--PTBoundry=3"
----PTBoundry=3
Content-Type: multipart/mixed;
boundary="--PTBoundry=2"
----PTBoundry=2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
TEST AF signed
----PTBoundry=2
Content-Type: application/octet-stream;
name=test2.txt
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=test2.txt
bWludGVzdGF0dGFjaG1lbnRzaWduZWQ=
----PTBoundry=2--
----PTBoundry=3
Content-Type: application/pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
MIIKfAYJKoZIhvcNAQcCoIIKbTCCCmkCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCCCNow
ggPVMIICvaADAgECAgMCNtEwDQYJKoZIhvcNAQEFBQAwQjELMAkGA1UEBhMCVVMxFjAUBgNVBAoT
PrENekpgrYkz
----PTBoundry=3--
empty line
I cannot figure out how to actually send this as an email. I am using MailMessage and I have tried to add it as written below:
var stream = new MemoryStream(Encoding.ASCII.GetBytes(message));
var view = new AlternateView(stream, "application/pkcs7-mime; smime-type=signed-data;name=smime.p7m");
however it does not work. The MailMessage adds different headers and messes it all up.
How can I send this correctly?
I am no longer using the MailMessage class, because I could not get it working.
Instead I am using EWS managed api like this:
var mail = new EmailMessage(_service);
mail.Subject = filename;
mail.MimeContent = new MimeContent("us-ascii", Encoding.ASCII.GetBytes(messageContentWithHeaders));
mail.SendAndSaveCopy();
Related
I have string data as CDATA Format. How can I convert this to Html or normal view text at C#? Should I use mimeKit or something else?
Received: from 172.19.76.148 (proxying for 85.105.234.193)
(InterKepWebMail authenticated user parkentegrasyon)
by kep.local with HTTP;
Mon, 29 Jan 2018 18:51:40 +0300
Content-Type: multipart/mixed;
boundary="------_=_NextPart_001_01F869E9.0A514C28"
Message-ID: <8ec68378-eca0-428d-a350-94427435a521.webmail#testkep.inter-kep.com.tr>
MIME-Version: 1.0
Date: Mon, 29 Jan 2018 18:51:40 +0300
From: "parkentegrasyon" <parkentegrasyon#testkep.inter-kep.com.tr>
To: <parkentegrasyon#testkep.inter-kep.com.tr>
Cc: <parkentegrasyon#testkep.inter-kep.com.tr>
Subject: =?utf-8?Q?=C3=96rnek_KEP_2018-01-29_18=3A51=3A41?=
User-Agent: InterKepWebMail/1.0.0
X-TR-REM-iletiTip: standart
X-TR-REM-iletiID:
--------_=_NextPart_001_01F869E9.0A514C28
Content-Type: text/html;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
<b>Merhaba D=C3=BCnya!</b>
--------_=_NextPart_001_01F869E9.0A514C28
Content-Type: application/octet-stream;
name="test.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="test.txt"
dGVzdCBlaw==
--------_=_NextPart_001_01F869E9.0A514C28--
If you use MimeKit to parse the message, it will automatically decode the content (whether it be in base64 or quoted-printable).
In your example message, the text/html message body can be gotten like this:
var html = message.HtmlBody;
To get the decoded attachment content, you can do this:
foreach (var attachment in message.Attachments.OfType<MimePart> ()) {
using (var memory = new MemoryStream ()) {
attachment.Content.DecodeTo (memory);
var data = memory.ToArray ();
var text = Encoding.UTF8.GetString (data);
}
}
It's base64 encoded text. You can decode it like this
byte[] data = Convert.FromBase64String("dGVzdCBlaw==");
string decodedString = Encoding.UTF8.GetString(data);
Console.WriteLine(decodedString);
That prints 'Test ek'.
I am trying to send an email with embedded image(Not as attachment file). I am able to send mail.
I'm sending mail using following code:
internal static void Send(SmtpServerConfigurations configurations, EmailMessage emailMsg)
{
using (var mail = InitializeMailMessage(emailMsg))
using (var smtpClient = CreateSmtpClient(configurations))
smtpClient.Send(mail);
}
private static MailMessage InitializeMailMessage(EmailMessage emailMsg)
{
var mail = new MailMessage
{
From = new MailAddress(emailMsg.From),
Subject = emailMsg.Subject,
IsBodyHtml = emailMsg.IsBodyHtml
};
mail.To.Add(emailMsg.To);
AddMessageBody(emailMsg, mail);
return mail;
}
private static void AddMessageBody(EmailMessage emailMsg, MailMessage mail)
{
if (emailMsg.IsBodyHtml)
{
var body = GetHtmlBody(emailMsg.Body, emailMsg.EmbeddedImages);
mail.AlternateViews.Add(body);
}
else
mail.Body = emailMsg.Body;
}
private static AlternateView GetHtmlBody(string body, List<EmbeddedImage> embeddedImages)
{
var alternateView = AlternateView.CreateAlternateViewFromString(body, null,
MediaTypeNames.Text.Html);
if (embeddedImages == null) return alternateView;
foreach (var image in embeddedImages)
{
var imageToInline = new LinkedResource(image.Path, MediaTypeNames.Image.Jpeg);
imageToInline.ContentId = image.Id;
alternateView.LinkedResources.Add(imageToInline);
}
return alternateView;
}
private static SmtpClient CreateSmtpClient(SmtpServerConfigurations config)
{
var smtpClient = new SmtpClient(config.Host);
smtpClient.Port = config.PortNo;
if (config.IsAuthenticationRequired)
smtpClient.Credentials =
new NetworkCredential(config.Username, config.Password);
else
smtpClient.UseDefaultCredentials = true;
smtpClient.EnableSsl = false;
return smtpClient;
}
But the mail sent using above code is not in the format as I want.
What I want is;
MIME-Version: 1.0
From: x#y.com
To: a#b.com
Date: 11 Nov 2016 11:37:52 +0530
Subject: This is subject
Content-Type: multipart/related;
boundary=--boundary_3_1bb3db0a-d33f-46a7-a6ce-60249096160d; type="text/html"
----boundary_3_1bb3db0a-d33f-46a7-a6ce-60249096160d
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN" "=
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xm=
lns =3D "http://www.w3.org/1999/xhtml" > <head ><meta http - equi=
v =3D "content-type" content =3D "text/html; charset=3DUTF-8" /><=
/head ><body style =3D"font-family: Segoe UI; text-align:left;" >=
This is body<br /><img alt =3D"" src =3D"cid:05393c56-15c1-4652-a=
31f-9cc513726bc0" height=3D"50" width=3D"50"/></body ></html >
----boundary_3_1bb3db0a-d33f-46a7-a6ce-60249096160d
Content-Type: image/jpeg name="filename.jpg" <<-----This is what I want.
Content-Transfer-Encoding: base64
Content-ID: <05393c56-15c1-4652-a31f-9cc513726bc0>
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMF
BwYHBwcGBwcI
.
.
.
/w20K7sPt8ul2st3/z0dd36Hj9K9I+HHwj8M6/rLaldaJp8l6y
kGRYgn6LgfpXve0pundwQmk9z//Z
----boundary_3_1bb3db0a-d33f-46a7-a6ce-60249096160d--
What I am getting is;
MIME-Version: 1.0
From: x#y.com
To: a#b.com
Date: 11 Nov 2016 11:37:52 +0530
Subject: This is subject
Content-Type: multipart/related;
boundary=--boundary_3_1bb3db0a-d33f-46a7-a6ce-60249096160d; type="text/html"
----boundary_3_1bb3db0a-d33f-46a7-a6ce-60249096160d
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN" "=
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xm=
lns =3D "http://www.w3.org/1999/xhtml" > <head ><meta http - equi=
v =3D "content-type" content =3D "text/html; charset=3DUTF-8" /><=
/head ><body style =3D"font-family: Segoe UI; text-align:left;" >=
This is body<br /><img alt =3D"" src =3D"cid:05393c56-15c1-4652-a=
31f-9cc513726bc0" height=3D"50" width=3D"50"/></body ></html >
----boundary_3_1bb3db0a-d33f-46a7-a6ce-60249096160d
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <05393c56-15c1-4652-a31f-9cc513726bc0>
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMF
BwYHBwcGBwcI
.
.
.
/w20K7sPt8ul2st3/z0dd36Hj9K9I+HHwj8M6/rLaldaJp8l6y
kGRYgn6LgfpXve0pundwQmk9z//Z
----boundary_3_1bb3db0a-d33f-46a7-a6ce-60249096160d--
How can I achieve that custom "Name" header in Embedded image section of raw mail?
I want to add that header is because;
When I click on download button shown on image in Gmail inbox, I get "noname" file without extension. That downloaded file isn't useful unless user changes its extension to '.jpg/.jpeg'.
When I tried the same with another component(Which I don't have code for) strangely I was able to download that image with correct filename. Only difference between these two mails was "Name" header.
Please suggest me how to do this or any other way to achieve it.
This will do the trick for you
imageToInline.ContentType.Name = "ImageName.jpg";
I want to send email using System.Web.Mail.MailMessage along with System.Web.Mail.SmtpMail class.
I know that this is a deprecated class but using System.Net.Mail is not an option for me.
So far I am able to send html formatted mail but I am not able to embed image to my email while sending.
This is what I've tried so far;
private static void SendMailMethod(string mailServer, int mailServerPort, string userName, string password)
{
const string SMTP_SERVER = "http://schemas.microsoft.com/cdo/configuration/smtpserver";
const string SMTP_SERVER_PORT =
"http://schemas.microsoft.com/cdo/configuration/smtpserverport";
const string SEND_USING = "http://schemas.microsoft.com/cdo/configuration/sendusing";
const string SMTP_USE_SSL = "http://schemas.microsoft.com/cdo/configuration/smtpusessl";
const string SMTP_AUTHENTICATE =
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate";
const string SEND_USERNAME =
"http://schemas.microsoft.com/cdo/configuration/sendusername";
const string SEND_PASSWORD =
"http://schemas.microsoft.com/cdo/configuration/sendpassword";
var mailMessage = new System.Web.Mail.MailMessage();
mailMessage.Fields[SMTP_SERVER] = mailServer;
mailMessage.Fields[SMTP_SERVER_PORT] = mailServerPort;
mailMessage.Fields[SEND_USING] = 2;
mailMessage.Fields[SMTP_USE_SSL] = false;
mailMessage.Fields[SMTP_AUTHENTICATE] = 0;
mailMessage.Fields[SEND_USERNAME] = userName;
mailMessage.Fields[SEND_PASSWORD] = password;
mailMessage.From = "abc#xyz.com";
mailMessage.To = "abc#xyz.com";
mailMessage.Subject = "Test mail:";
mailMessage.BodyFormat = MailFormat.Html;
var mailAttachment = new MailAttachment("E:\\imageToEmbed.jpg");
mailMessage.Attachments.Add(mailAttachment);
mailMessage.Attachments.Add(new MailAttachment("E:\\TestAttachmentFile.txt"));
var htmlBody =
"<!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" +
"<html xmlns = \"http://www.w3.org/1999/xhtml\" >" +
" <head >" +
"<meta http - equiv = \"content-type\" content = \"text/html; charset=UTF-8\" />" +
"</head >" +
"<body style = \"font-family: Segoe UI; text-align:left;\" >" +
"Following is an embedded image:" +
"<br />" +
"<img alt = \"\" src = \"imageToEmbed.jpg\" />" +
"</body >" +
"</html >";
mailMessage.Body = htmlBody;
try
{
SmtpMail.Send(mailMessage);
Console.WriteLine("Mail sent");
}
catch (Exception ex)
{
Console.WriteLine("Error:" + ex.ToString());
throw ex;
}
}
This code sends email but instead of showing image, the mail shows small square with a cross in it.
How can I embed this "imageToEmbed.jpg" to my email.
You can't achieve that with the classes System.Web.Mail because that implementation abstracts the access to a lot of features of the underlying Collaboration Data Objects component.
Instead of using the wrapper offered by System.Web.Mail.Message you better switch to using the CDO COM object directly. Add a reference to Microsoft CDO for Windows 2000 Library from the COM tab in the reference dialog.
After that you can use the following code to create and send an html email with embedded images:
var cdo = new CDO.Message();
// configuration
var cfg = cdo.Configuration;
cfg.Fields[SMTP_SERVER].Value = "smtp.server.com";
cfg.Fields[SMTP_SERVER_PORT].Value = 22;
cfg.Fields[SEND_USING].Value = 2;
cfg.Fields[SMTP_USE_SSL].Value = true;
cfg.Fields[SMTP_AUTHENTICATE].Value = 1;
cfg.Fields[SEND_USERNAME].Value = "user#example.com";
cfg.Fields[SEND_PASSWORD].Value = "password";
cfg.Fields.Update();
cdo.To = "awesome#example.com";
cdo.Sender = "me#example.com";
// attachment
var cdoatt = cdo.AddAttachment("file:///E:/imageToEmbed.jpg");
//this is why System.Web.Mail can't embed images
cdoatt.Fields["urn:schemas:mailheader:content-id"].Value = Guid.NewGuid().ToString("N");
cdoatt.Fields.Update();
// get a reference to out content-id field
var cid = cdoatt.Fields["urn:schemas:mailheader:content-id"];
// notice the special layout of SRC on the image tag,
//it will be somethong like CID:123456789abcdef
cdo.HTMLBody = #"<HTML><BODY><B>CDO</B><BR /> <IMG SRC=""cid:" + cid.Value + #"""/></BODY></HTML>";
cdo.Send();
Notice how you can set the Content-ID header here on the Attachment. That is needed so you can use the Content-ID in the SRC attribute of your image.
A typical mailmessage will look
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_000_0001_01D1AF72.C8AE8C70"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V10.0.10011.16384
This is a multi-part message in MIME format.
------=_NextPart_000_0001_01D1AF72.C8AE8C70
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_0002_01D1AF72.C8AE8C70"
------=_NextPart_001_0002_01D1AF72.C8AE8C70
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
plain cdo
------=_NextPart_001_0002_01D1AF72.C8AE8C70
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<HTML><BODY><B>plain cdo</B> <IMG SRC="cid:42"/></BODY></HTML>
------=_NextPart_001_0002_01D1AF72.C8AE8C70--
------=_NextPart_000_0001_01D1AF72.C8AE8C70
Content-Type: image/png;
name="file.png"
Content-Transfer-Encoding: base64
Content-ID: <42>
Content-Disposition: attachment;
filename="file.png"
iVBORw0KGgoAAAANSUhEUgAAADQAAABLCAMA
Notice the Content-ID (here 42).
When using the plain System.Web.Mail classes your raw email will look like this:
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_NextPart_000_0000_01D1AF70.59FC25F0"
X-Mailer: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V10.0.10011.16384
This is a multi-part message in MIME format.
------=_NextPart_000_0000_01D1AF70.59FC25F0
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_0001_01D1AF70.59FC25F0"
------=_NextPart_001_0001_01D1AF70.59FC25F0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Following is an embedded image:
_____
test afterit
------=_NextPart_001_0001_01D1AF70.59FC25F0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns = "http://www.w3.org/1999/xhtml" > <head ><meta http - equiv = "content-type" content = "text/html; charset=UTF-8" /></head ><body style = "font-family: Segoe UI; text-align:left;" ><i>Following is an embedded image:</i><br /><img alt = "" src ="<file:///file.png>"/><hr><b>test afterit</b></body ></html >
------=_NextPart_001_0001_01D1AF70.59FC25F0--
------=_NextPart_000_0000_01D1AF70.59FC25F0
Content-Type: image/png;
name="file.png"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="file.png"
iVBORw0KGgoAAAANSUhEUgAAADQAAABLCAMAAAAI0l
As you can see, there is no Content-ID header added and there is no code-path from the .Net implementation to add that header.
It might not find the image in the specified path or it might be a permission thing hence the broken image thingy. You need to check that first but if you would use base64 you will have the image in a string.
Try changing the image to a base64 link to a free online converter page.
This link might help as well c# embed base64 image for emailing.
I am trying to flash a spark core from a C# application. I keep getting { error: Nothing to do? } response.
Below is my code
var url = string.Format("https://api.spark.io/v1/devices/{0}", sparkDeviceID);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accesstoken);
using (var formData = new MultipartFormDataContent())
{
HttpContent fileContent = new ByteArrayContent(Encoding.ASCII.GetBytes(rom));
//client.SendAsync()
formData.Add(fileContent, "file", "file");
var response = client.PutAsync(url, formData).Result;
if (!response.IsSuccessStatusCode)
throw new Exception("An error occurred during rom flash!");
var responseStream = response.Content.ReadAsStreamAsync().Result;
using (var reader = new StreamReader(responseStream, true))
{
var result = reader.ReadToEnd();
}
}
return true;
}
The documentation reads:
The API request should be encoded as multipart/form-data with a file field populated.
I believe the problem is the endpoint doesn't see the file. Any idea on how to resolve this?
Finally got it working.
The issue was the way .NET generated the content-disposition header for the file form data.
I used fiddler to compare the output of a successful put request to the put request that my code was generating:
Successful PUT request generated using CURL:
PUT http://127.0.0.1:8888/ HTTP/1.1
User-Agent: curl/7.33.0
Host: 127.0.0.1:8888
Accept: */*
Content-Length: 2861
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------5efcf64a370f13c8
--------------------------5efcf64a370f13c8
Content-Disposition: form-data; name="file"; filename="ms.ino"
Content-Type: application/octet-stream
...
My PUT request (unsuccessful):
PUT https://api.spark.io/v1/devices/{deviceid} HTTP/1.1
Authorization: Bearer {access_token}
Content-Type: multipart/form-data; boundary="135f5425-9342-4ffa-a645-99c04834026f"
Host: api.spark.io
Content-Length: 2878
Expect: 100-continue
--135f5425-9342-4ffa-a645-99c04834026f
Content-Type: application/octet-stream
Content-Disposition: form-data; name=file; filename=file.ino; filename*=utf-8''file.ino
...
If you'll notice the difference in the Content-Type for the actual file being sent:
Successful: Content-Disposition: form-data; name="file"; filename="ms.ino"
Unsuccessful: Content-Disposition: form-data; name=file; filename=file.ino; filename*=utf-8''file.ino
Most specifically, the resolution was to add quotes around the name attribute.
Resolution:
formData.Add(fileContent, "\"file\"", "file.ino");
I want to create an application to automaticly upload a file to googles SearchbyImage-tool
https://www.google.de/searchbyimage/upload
Google is using a multipart/form-data for submitting the file, something like that:
Content-Type: multipart/form-data; boundary=---------------------------265001916915724
Content-Length: 9989
-----------------------------265001916915724
Content-Disposition: form-data; name="image_url"
-----------------------------265001916915724
Content-Disposition: form-data; name="encoded_image"; filename=""
Content-Type: application/octet-stream
-----------------------------265001916915724
Content-Disposition: form-data; name="image_content"
iVBORw0KGgoAAAANSUhEUgAAA7sAAAAdCA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yND4iEHoiwwCrV_KcKAMh74dYab5ufjmJ-fJcSivqsmWPzhgn1vfcAq__PXUnq2xtcqAaL-nDCfCV_0XXzFndxQzFPKSERx6T_IgfaD1QPaA7CHtB7QfEh4gPEB4gPAA4QHCA_0bDwhnV0asnE2N3pM8SB9oPSgdIHtA9oDsAdkDsgdSB8gekj0ke0j2kOxh_7KHwtmliEX_jljQ_NH8EQNFDBQxUMRA0X5OeIbwAOEBwgOEBwgPuPGAK42ZIpYUsaSIJUUsKWLZvyKWNF80X8Q4EuNK-I3wG-E3wm-EB8x4gGp2qUaZarapZp1q9inDhTJ86MwKOrOD8ADhAcIDhAcIDww4PEA1u1SDQzVIVLNONft0ZoGtA8QQEUNEDBExRMQQUcYIZYxQxshAwQP_D1qk899cHOG9AAAAAElFTkSuQmCC
-----------------------------265001916915724
Content-Disposition: form-data; name="filename"
filename.bmp
-----------------------------265001916915724
Content-Disposition: form-data; name="num"
10
-----------------------------265001916915724
Content-Disposition: form-data; name="hl"
de
-----------------------------265001916915724
Content-Disposition: form-data; name="bih"
976
-----------------------------265001916915724
Content-Disposition: form-data; name="biw"
1920
-----------------------------265001916915724--
I have absolutely no idea on how to do that in C#... Any suggestions?
using c# you can use HttpClient to do the Post Multi-part Form Data.
below is the code snippet that i tried and worked for me..
give it a try!!
using (var client = new HttpClient())
{
//client.DefaultRequestHeaders.Add("User-Agent", "CBS Brightcove API Service");
string authorization = GenerateBase64();
client.DefaultRequestHeaders.Add("Authorization", authorization);
using (var content = new MultipartFormDataContent())
{
string fileName = Path.GetFileName(textBox1.Text);
//Content-Disposition: form-data; name="json"
var stringContent = new StringContent(InstancePropertyObject);
stringContent.Headers.Remove("Content-Type");
stringContent.Headers.Add("Content-Type", "application/json");
stringContent.Headers.Add("Content-Disposition", "form-data; name=\"instance\"");
content.Add(stringContent, "instance");
var fileContent = new ByteArrayContent(filecontent);
fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = fileName
};
content.Add(fileContent);
var result = client.PostAsync(targetURL, content).Result;
Console.Read();
}
}
You could use WebClient's upload file method. You could use headers property to assign packet's headers. A few caveats with WebClient are: setting timeout, unzipping gzipped responses and finally if you intend to make multiple simultaneous requests removing connections limit