Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
Send attachment using HttpClient
Jassim Rahma
Dec 16 2017 12:46 PM
209
Reply
Hi,
I am using below code to send email using Mailgun and HttpClient.
I now have an image on my page which is imgProfile and I want to send this image as an attachment in the same code.
How can Id o that please?
async Task<HttpStatusCode> SendMessage()
{
try
{
loadingShareQRCode.IsBusy =
true
;
var client =
new
HttpClient();
client.DefaultRequestHeaders.Authorization =
new
AuthenticationHeaderValue(
"Basic"
, Convert.ToBase64String(UTF8Encoding.UTF8.GetBytes(
"api"
+
":"
+
"key-xxxxxxxxxxxxx"
)));
var form =
new
Dictionary<
string
,
string
>();
form[
"from"
] =
"Zeera <
[email protected]
>"
;
// form["to"] = the_name + " <" + the_email + ">";
// form["from"] = Convert.ToString(App.Current.Properties["ZeeraCustomerFirstName"]) + " " + Convert.ToString(App.Current.Properties["ZeeraCustomerLastName"]) + " <" + Convert.ToString(App.Current.Properties["ZeeraCustomerEmail"]) + ">";
form[
"to"
] = txtShareQRCodeName.Text +
" <"
+ txtShareQRCodeEmail.Text +
">"
;
form[
"subject"
] = txtShareQRCodeSubject.Text;
body =
"<html dir='ltr' lang='en'>"
;
body +=
"<head>"
;
body +=
"<meta charset='UTF-8'>"
;
body +=
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>"
;
body +=
"</head>"
;
body +=
"<body dir='ltr' lang='en'>"
;
body +=
"Dear "
+ txtShareQRCodeName.Text +
"<br /><br />"
;
body += Convert.ToString(App.Current.Properties[
"ZeeraCustomerFirstName"
]) +
" has sent you the attached Zeera QR code with below details:"
;
// body += txtContactZeeraMessage.Text;
body +=
"</body>"
;
body +=
"</html>"
;
form[
"html"
] = Regex.Replace(body, @
"\r\n?|\n"
,
"<br />"
);
var response = await client.PostAsync(
"https://api.mailgun.net/v2/"
+
"reach.softnames.com"
+
"/messages"
,
new
FormUrlEncodedContent(form));
return
response.StatusCode;
}
catch
{
loadingShareQRCode.IsVisible =
false
;
loadingShareQRCode.IsBusy =
false
;
btnShareQRCodeSend.IsVisible =
true
;
}
return
HttpStatusCode.Unused;
}
Thanks,
Jassim
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to map fields in an object to another dynamically?
Bootstrap datetime picker not working properly in iphone7