public static string Run( [ActivityTrigger] OrdiniAcquistoModel ordiniAcquisto, [OrchestrationClient] DurableOrchestrationClient starter, [SendGrid(ApiKey = "SendGridApiKey")] ICollector <SendGridMessage> messageCollector) { string toMail = Utility.GetEnvironmentVariable("SendGridTo"); string fromMail = Utility.GetEnvironmentVariable("SendGridFrom"); var message = new SendGridMessage { Subject = $"WPC 2018" }; message.AddTo(toMail); Content content = new Content { Type = "text/html", Value = $@"L'ordine {ordiniAcquisto.IdOrdine} è stato preso in carico <br><a href='{Utility.GetEnvironmentVariable("PublicUrl")}/ApprovaOrdine?ordineId={ordiniAcquisto.IdConfirmation}'>Conferma ordine</a>" }; message.From = new EmailAddress(fromMail); message.AddContents(new [] { content }.ToList()); messageCollector.Add(message); return(Guid.NewGuid().ToString("N")); }
public async Task <IActionResult> ContactUs(string mailBody) { try { var apiKey = this.Configuration.GetValue <string>("SendGridApi"); var client = new SendGridClient(apiKey); // Send a Single Email using the Mail Helper with convenience methods and initialized SendGridMessage object var msg = new SendGridMessage() { From = new EmailAddress(this.Configuration.GetValue <string>("FromEmail")), Subject = this.Configuration.GetValue <string>("ContactSubject") }; Content mailContent = new Content("text/html", mailBody); msg.AddTo(new EmailAddress(this.Configuration.GetValue <string>("ToEmail"))); msg.AddContents(new List <Content>() { mailContent }); var response = await client.SendEmailAsync(msg); return(Ok(response.StatusCode)); } catch (Exception ex) { return(BadRequest()); } }
public static void CreateCompleteEmail( List <Content> outgoingBodies, List <EmailAddress> recipients, SendGridMessage mailMessage, OrderTable orderTable, string myBlob) { outgoingBodies.Add(new Content( "text/plain", orderTable.Message + "\n\n" + "Blob size: " + myBlob.Length * 2 + "bytes")); recipients.Add(new EmailAddress(orderTable.ToEmail)); mailMessage.AddTos(recipients); mailMessage.AddContents(outgoingBodies); mailMessage.SetFrom(new EmailAddress(orderTable.FromEmail)); mailMessage.SetSubject("Mottagen order"); var attach = CreateAttachment(myBlob); mailMessage.AddAttachment(attach); }
public async Task <IActionResult> ApplyJob(string mailBody) { try { var apiKey = this.Configuration.GetValue <string>("SendGridApi"); var client = new SendGridClient(apiKey); // Send a Single Email using the Mail Helper with convenience methods and initialized SendGridMessage object var msg = new SendGridMessage() { From = new EmailAddress(this.Configuration.GetValue <string>("FromEmail"), "no-reply"), Subject = this.Configuration.GetValue <string>("ApplySubject") }; Content mailContent = new Content("text/html", mailBody); msg.AddTo(new EmailAddress(this.Configuration.GetValue <string>("ToEmail"))); msg.AddContents(new List <Content>() { mailContent }); var file = Request.Form.Files[0].OpenReadStream(); string files; using (MemoryStream ms = new MemoryStream()) { string fileName = Request.Form.Files[0].FileName; file.CopyTo(ms); var bytes = ms.ToArray(); files = Convert.ToBase64String(bytes); msg.AddAttachment(fileName, files); } var response = await client.SendEmailAsync(msg); return(Ok(response.StatusCode)); } catch (Exception ex) { return(BadRequest()); } }