예제 #1
0
        private static void SendImageSet(EmailMessageContent emailMessageContent)
        {
            var multipartContent = new MultipartFormDataContent();

            var emailMessageContentJson = JsonConvert.SerializeObject(emailMessageContent,
                                                                      new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            multipartContent.Add(
                new StringContent(emailMessageContentJson, Encoding.UTF8, "application/json"),
                "emailmessagecontent"
                );

            int counter = 0;

            foreach (var iAttachment in emailMessageContent.Attachments)
            {
                var fileContent = new ByteArrayContent(iAttachment.FileData);
                fileContent.Headers.ContentType = new MediaTypeHeaderValue(iAttachment.MimeType);
                multipartContent.Add(fileContent, "image" + counter++, iAttachment.FileName);
            }

            var response = new HttpClient()
                           .PostAsync("http://localhost:48000/api/EmailServiceAPI/test", multipartContent)
                           .Result;

            var responseContent = response.Content.ReadAsStringAsync().Result;

            Trace.Write(responseContent);
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var emailMessageContent = new EmailMessageContent()
            {
                From        = "*****@*****.**",
                To          = "*****@*****.**",
                Subject     = "Email Quote",
                Body        = "Test",
                Attachments = Directory
                              .EnumerateFiles("C:\\Users\\i805597\\Pictures")
                              .Where(file => new[] { ".jpg", ".png" }.Contains(Path.GetExtension(file)))
                              .Select(file => new FileAttachment
                {
                    FileName = Path.GetFileName(file),
                    MimeType = MimeMapping.GetMimeMapping(file),
                    FileData = File.ReadAllBytes(file)
                })
                              .ToList()
            };

            SendImageSet(emailMessageContent);
        }