TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jassim Rahma
NA
48
0
Send attachment using HttpClient
Dec 16 2017 12:46 PM
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
Reply
Answers (
1
)
How to map fields in an object to another dynamically?
browse to open two excel file and add filter remove column