public async Task SendEmail(string fromEmail, string fromName, string htmlEmailBody, string plaintextEmailBody, IEnumerable <Tuple <string, string> > emailTos, string emailSubject)
        {
            var client = new SendGridClient(APIKey);
            var msg    = new SendGridMessage();

            msg = new SendGridMessage();
            msg.SetFrom(new EmailAddress(fromEmail, fromName));
            msg.SetSubject(emailSubject);
            if (!string.IsNullOrWhiteSpace(htmlEmailBody))
            {
                msg.AddContent(MimeType.Html, htmlEmailBody);
            }
            else
            {
                msg.AddContent(MimeType.Text, plaintextEmailBody);
            }

            emailTos.ToList().ForEach((receipient) =>
            {
                msg.AddTo(new EmailAddress(receipient.Item1, receipient.Item2));
            });
            await client.SendEmailAsync(msg);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method from the IEMailSender
        /// </summary>
        /// <param name="email">email</param>
        /// <param name="subject">subject of the email</param>
        /// <param name="htmlMessage">content of the email</param>
        /// <returns></returns>
        public async Task SendEmailAsync(string email, string subject, string htmlMessage)
        {
            // injecting the api key from sendgrid
            SendGridClient  client = new SendGridClient(_configuration["SendGrid-Key"]);
            SendGridMessage msg    = new SendGridMessage();

            //First param is email and second is email
            msg.SetFrom("*****@*****.**", "QuikFix");
            msg.AddTo(email);
            msg.SetSubject(subject);
            msg.AddContent(MimeType.Html, htmlMessage);

            await client.SendEmailAsync(msg);
        }
Ejemplo n.º 3
0
        public async Task SendEmailAsync(string email, string subject, string htmlMessage)
        {
            var client = new SendGridClient(Configuration["SendGrid"]);

            var msg = new SendGridMessage();

            msg.SetFrom("*****@*****.**", "RuckSack Customer Service");

            msg.AddTo(email);
            msg.SetSubject(subject);
            msg.AddContent(MimeType.Html, htmlMessage);

            var response = await client.SendEmailAsync(msg);
        }
Ejemplo n.º 4
0
        private static SendGridMessage CreateSingleEmail(EmailAddress from,
                                                         EmailAddress to,
                                                         string subject,
                                                         string plainTextContent,
                                                         string htmlContent)
        {
            var msg = new SendGridMessage();

            msg.SetFrom(from);
            msg.SetSubject(subject);
            if (!string.IsNullOrEmpty(plainTextContent))
            {
                msg.AddContent(MimeType.Text, plainTextContent);
            }

            if (!string.IsNullOrEmpty(htmlContent))
            {
                msg.AddContent(MimeType.Html, htmlContent);
            }

            msg.AddTo(to);
            return(msg);
        }
Ejemplo n.º 5
0
        public void SendEmail(string subject, string message, Account to)
        {
            var msg = new SendGridMessage();

            msg.SetFrom(new EmailAddress("*****@*****.**", "Igloo smart home"));
            msg.AddTo(to.Email);
            msg.SetSubject(subject);
            msg.AddContent(MimeType.Html, message);

            var apiKey = System.Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
            var client = new SendGridClient(apiKey);

            client.SendEmailAsync(msg);
        }
Ejemplo n.º 6
0
        public async Task SendEmailAsync(string email, string subject, string htmlMessage)
        {
            var client = new SendGridClient(Configuration["Api_Key"]);

            var msg = new SendGridMessage();

            msg.SetFrom("*****@*****.**", "Bus Mall Admin");

            msg.AddTo(email);
            msg.SetSubject(subject);
            msg.AddContent(MimeType.Html, htmlMessage);

            var response = await client.SendEmailAsync(msg);
        }
        public static void SendReleaseEmail([ActivityTrigger] Release releaseData,
                                            [SendGrid] out SendGridMessage sendGridMessage,
                                            ILogger log)
        {
            log.LogInformation($"[ENTER] Sending release notification email for releaseTag: {releaseData.ReleaseTag}");
            sendGridMessage = new SendGridMessage();

            sendGridMessage.AddTo("*****@*****.**");
            sendGridMessage.AddContent("text/html", $"{FormatContent(releaseData)}");
            sendGridMessage.SetFrom("*****@*****.**");
            sendGridMessage.SetSubject($"Release for {releaseData.ReleaseTag}");

            log.LogInformation($"[END] Sending release notification email for releaseTag: {releaseData.ReleaseTag}");
        }
Ejemplo n.º 8
0
        public static void Run([CosmosDBTrigger(
                                    databaseName: "quotedemo",
                                    collectionName: "quotes",
                                    ConnectionStringSetting = "CosmosConnection",
                                    LeaseCollectionName = "leases")] IReadOnlyList <Document> input, [SendGrid(From = "%NotificationsSender%")] out SendGridMessage message, TraceWriter log)
        {
            var messageRecipient = input[0].GetPropertyValue <string>("recipient");
            var messageBody      = input[0].GetPropertyValue <string>("quote");

            message = new SendGridMessage();
            message.AddContent("text/plain", messageBody);
            message.AddTo(messageRecipient);
            message.Subject = "Funny Quote of the day";
        }
Ejemplo n.º 9
0
        //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
        static void Main(string[] args)
        {
            var msg    = new SendGridMessage();
            var client = new SendGridClient("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");

            msg.SetFrom(new EmailAddress("*****@*****.**", "Ashish Mathur"));

            var recipients = new List <EmailAddress>
            {
                new EmailAddress("*****@*****.**", "Ashish Mathur"),
                new EmailAddress("*****@*****.**", "Ashish Mathur"),
            };

            msg.AddTos(recipients);

            msg.SetSubject("Testing Sendgrid domain authentication");

            msg.AddContent(MimeType.Text, "Hello World plain text!");
            msg.AddContent(MimeType.Html, "<p>Hello World!</p>");
            client.SendEmailAsync(msg);
            Console.WriteLine("-- Done --");
            Console.ReadLine();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Send an email to the user
        /// </summary>
        /// <param name="email"></param>
        /// <param name="subject"></param>
        /// <param name="htmlMessage"></param>
        /// <returns></returns>
        public async Task SendEmailAsync(string email, string subject, string htmlMessage)
        {
            SendGridClient client = new SendGridClient(_configuration["Sendgrid_Api_Key"]);

            SendGridMessage msg = new SendGridMessage();

            msg.SetFrom("*****@*****.**", "Good Toyes Admin");

            msg.AddTo(email);
            msg.SetSubject(subject);
            msg.AddContent(MimeType.Html, htmlMessage);

            await client.SendEmailAsync(msg);
        }
Ejemplo n.º 11
0
        private SendGridMessage CreateEmail(string email, string subject, string message)
        {
            var msg = new SendGridMessage();

            msg.SetFrom(new EmailAddress("*****@*****.**", "Tallan"));

            msg.AddTo(email);

            msg.SetSubject(subject);

            msg.AddContent(MimeType.Html, message);

            return(msg);
        }
Ejemplo n.º 12
0
        internal static void DefaultMessageProperties(SendGridMessage mail, SendGridOptions options, SendGridAttribute attribute)
        {
            // Apply message defaulting
            if (mail.From == null)
            {
                if (!string.IsNullOrEmpty(attribute.From))
                {
                    EmailAddress from = null;
                    if (!TryParseAddress(attribute.From, out from))
                    {
                        throw new ArgumentException("Invalid 'From' address specified");
                    }
                    mail.From = from;
                }
                else if (options.FromAddress != null)
                {
                    mail.From = options.FromAddress;
                }
            }

            if (!IsToValid(mail))
            {
                if (!string.IsNullOrEmpty(attribute.To))
                {
                    EmailAddress to = null;
                    if (!TryParseAddress(attribute.To, out to))
                    {
                        throw new ArgumentException("Invalid 'To' address specified");
                    }

                    mail.AddTo(to);
                }
                else if (options.ToAddress != null)
                {
                    mail.AddTo(options.ToAddress);
                }
            }

            if (string.IsNullOrEmpty(mail.Subject) &&
                !string.IsNullOrEmpty(attribute.Subject))
            {
                mail.Subject = attribute.Subject;
            }

            if ((mail.Contents == null || mail.Contents.Count == 0) &&
                !string.IsNullOrEmpty(attribute.Text))
            {
                mail.AddContent("text/plain", attribute.Text);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// SendGrid email setup
        /// </summary>
        /// <param name="email"></param>
        /// <param name="subject"></param>
        /// <param name="htmlMessage"></param>
        /// <returns>no return</returns>
        public async Task SendEmailAsync(string email, string subject, string htmlMessage)
        {
            var msg = new SendGridMessage();

            msg.SetFrom("*****@*****.**", "Mister Arigato Roboto Admin");

            msg.AddTo(email);
            msg.SetSubject(subject);
            msg.AddContent(MimeType.Html, htmlMessage);

            var client = new SendGridClient(Configuration["API_KEY"]);

            var response = await client.SendEmailAsync(msg);
        }
Ejemplo n.º 14
0
 public void FeedbackPost(
     [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "feedback")] FeedbackDto request,
     [SendGrid] out SendGridMessage message,
     ILogger log,
     ClaimsPrincipal principal
     )
 {
     message = new SendGridMessage();
     message.AddTo(Environment.GetEnvironmentVariable("FeedbackRecipient"));
     message.AddContent("text/html", request.Message);
     message.SetFrom(request.Email);
     message.SetSubject("Feedback for MaintenanceTracker");
     log.LogInformation($"Sending feedback message from anonymous user");
 }
Ejemplo n.º 15
0
        public async Task <bool> SendEmailAsync(string recipientEmail, string recipientName, string subject, string body)
        {
            _logger.LogInformation("Sending email message");

            if (string.IsNullOrWhiteSpace(_configuration.SendGridApiKey))
            {
                _logger.LogWarning($"Missing SendGridApiKey setting in {nameof(EmailNotifications)}");

                return(false);
            }

            if (string.IsNullOrWhiteSpace(_configuration.FromEmailAddress))
            {
                _logger.LogWarning($"Missing from FromEmailAddress setting in {nameof(EmailNotifications)}");

                return(false);
            }

            if (string.IsNullOrWhiteSpace(recipientEmail))
            {
                _logger.LogWarning("Missing recipient email, email message not sent");

                return(false);
            }

            //if (string.IsNullOrWhiteSpace(recipientName))
            //{
            //    _logger.LogWarning("Missing recipient name, email message not sent");

            //    return false;
            //}

            var message = new SendGridMessage();
            var from    = new EmailAddress(_configuration.FromEmailAddress, _configuration.FromName);
            var to      = new EmailAddress(recipientEmail, recipientName);

            message.SetFrom(from);
            message.AddTo(to);
            message.SetSubject(subject);
            message.AddContent(MimeType.Html, body);

            var client = new SendGridClient(_configuration.SendGridApiKey);

            var response = await client.SendEmailAsync(message);

            _logger.LogInformation($"Sent email form {from.Email} to {to.Email} response {response.StatusCode}");

            return(response.StatusCode == HttpStatusCode.OK);
        }
        internal async Task BuildAndSendEmail(EmailBuildingResult result, IEnumerable <Mentor> mentorsFromDB)
        {
            var mentors     = new Dictionary <string, string>();
            var apiKey      = Environment.GetEnvironmentVariable("EMAILAPIKEY", EnvironmentVariableTarget.Process);
            var emailSender = Environment.GetEnvironmentVariable("EMAILSENDER", EnvironmentVariableTarget.Process);

            var client = new SendGridClient(apiKey);

            var icsAttachment = new Attachment()
            {
                Content     = Convert.ToBase64String(Encoding.UTF8.GetBytes(result.CalendarItem.ToString())),
                Type        = "text/calendar",
                Filename    = "meeting.ics",
                Disposition = "inline",
                ContentId   = "Attachment"
            };

            var msg = new SendGridMessage();

            msg.SetFrom(new EmailAddress(emailSender, "CoderDojo"));
            msg.SetSubject("Dein CoderDojo Online Workshop");
            msg.AddAttachment(icsAttachment);

            var mentorFromDB = mentorsFromDB.FirstOrDefault(mdb => mdb.firstname == result.MentorName);

            if (mentorFromDB == null)
            {
                return;
            }

            mentors.Add(mentorFromDB.nickname, mentorFromDB.email);
            msg.AddTo(new EmailAddress(mentors[mentorFromDB.firstname]));
            msg.AddContent(MimeType.Text, result.EmailContent);
            msg.AddContent(MimeType.Html, result.EmailContent);
            var response = await client.SendEmailAsync(msg);
        }
Ejemplo n.º 17
0
        public async Task SendAsync(Email email, string fromEmail = null, CancellationToken cancellation = default)
        {
            // Prepare the SendGridMessage
            var msg = new SendGridMessage();

            msg.SetFrom(new EmailAddress(email: fromEmail ?? _options.DefaultFromEmail, name: _options.DefaultFromName));
            msg.AddTo(new EmailAddress(email.ToEmail));
            msg.SetSubject(email.Subject);
            msg.AddContent(MimeType.Html, email.Body);
            msg.AddCustomArg(EmailIdKey, email.EmailId.ToString());
            msg.AddCustomArg(TenantIdKey, email.TenantId.ToString());

            // Send it to SendGrid using their official C# library
            await SendEmailAsync(msg, cancellation);
        }
Ejemplo n.º 18
0
        public IActionResult Contact()
        {
            var msg = new SendGridMessage();

            msg.SetFrom(new EmailAddress("*****@*****.**", "SendGrid DX Team"));

            var recipients = new List <EmailAddress>
            {
                new EmailAddress("*****@*****.**", "Jeff Smith"),     //Change the email here to receive the contact us email
                new EmailAddress("*****@*****.**", "Anna Lidman"),
                new EmailAddress("*****@*****.**", "Peter Saddow")
            };

            msg.AddTos(recipients);

            msg.SetSubject("Testing the SendGrid C# Library");

            msg.AddContent(MimeType.Text, "Hello World plain text!");
            msg.AddContent(MimeType.Html, "<p>Hello World!</p>");



            return(View());
        }
        public async Task <IActionResult> PostMessage([FromBody] Message message)
        {
            var msg = new SendGridMessage();

            msg.SetFrom(new EmailAddress(message.Email, message.Name));

            msg.AddTo(new EmailAddress("*****@*****.**", "Ken Spur"));

            msg.SetSubject($"{message.Name} - Contact Form");
            msg.AddContent(MimeType.Text, message.Text);

            await new SendGridClient(_options.ApiKey).SendEmailAsync(msg);

            return(Ok());
        }
Ejemplo n.º 20
0
    public static async Task Submit_Form(string in_name, string in_email, string in_subject, string in_message)
    {
        var apikey = System.Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
        var client = new SendGridClient(apikey);

        var message = new SendGridMessage();

        message.SetFrom(new EmailAddress("*****@*****.**", "Contact Us"));
        message.AddTo(new EmailAddress("*****@*****.**", "Contact Us"));
        message.SetReplyTo(new EmailAddress(in_email, in_name));
        message.SetSubject(in_subject);
        message.AddContent(MimeType.Text, "Dear B-MHAC, \n\n" + in_message + "\n\nFrom, \n" + in_name);

        var response = await client.SendEmailAsync(message);
    }
Ejemplo n.º 21
0
        /// <summary>
        /// Send Email Via Rest API Service
        /// </summary>
        /// <param name="email"></param>
        /// <param name="subject"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task SendEmail(string email, string subject, string message)
        {
            var sendGridMessage = new SendGridMessage
            {
                From = new EmailAddress(_setting.SendGridSenderEmail),

                Subject = subject
            };

            sendGridMessage.AddTo(new EmailAddress(email));

            sendGridMessage.AddContent(MimeType.Html, message);

            await _sendGridClient.SendEmailAsync(sendGridMessage).ConfigureAwait(false);
        }
        public static void EmailNewContact(
            [QueueTrigger("fabsqueue-sendgridemail", Connection = "AzureWebJobsStorage")] Contact myQueueItem,
            TraceWriter log,
            [SendGrid()] out SendGridMessage message)
        {
            string emailBody = File.ReadAllText(@"D:\home\site\wwwroot\emailBody.txt");
            string b64vCard  = Environment.GetEnvironmentVariable("FabB64EncodedVCard");

            message = new SendGridMessage();
            message.AddTo(myQueueItem.EmailAddress);
            message.AddContent("text/html", emailBody);
            message.SetFrom(new EmailAddress("*****@*****.**"));
            message.SetSubject($"Great connecting with you {myQueueItem.FirstName} from Fabian Williams ");
            message.AddAttachment(@"FabianWilliams_PersonalvCard.vcf", b64vCard);
        }
Ejemplo n.º 23
0
        private async static Task <SendGridMessage> CreateMailAsync(
            Invoice invoice,
            Stream invoiceStream)
        {
            SendGridMessage message = new SendGridMessage();

            message.SetFrom(new EmailAddress("*****@*****.**", "Sender"));
            message.SetSubject($"Invoice {invoice.ID}");
            message.AddTo(new EmailAddress(invoice.MailTo, "Receiver"));

            message.AddContent("text/html", $"<strong>Invoice {invoice.ID}.</strong>");
            await message.AddAttachmentAsync($"{invoice.ID}.pdf", invoiceStream);

            return(message);
        }
Ejemplo n.º 24
0
        public SendGridMessage Run([ActivityTrigger] Catalogue filteredCatalogue)
        {
            #region null checks
            if (filteredCatalogue is null)
            {
                throw new ArgumentNullException(nameof(filteredCatalogue));
            }
            #endregion

            var summary = S.Plural(filteredCatalogue.Items.Count, "Catalogue Scanner found 1 matching item at {1}", "Catalogue Scanner found {0} matching items at {1}", filteredCatalogue.Store);

            var message = new SendGridMessage()
            {
                From    = new EmailAddress(FromEmail, FromName),
                Subject = summary,
            };

            message.AddTo(options.ToEmail, options.ToName);

            message.AddContent(MimeType.Html, GetHtmlContent(summary !, filteredCatalogue));
            message.AddContent(MimeType.Text, GetPlainTextContent(summary !, filteredCatalogue));

            return(message);
        }
        public static async Task SendCompletionEmail(
            [ActivityTrigger] Tuple <string, string> input,
            [SendGrid(ApiKey = "SendGridApiKey")] IAsyncCollector <SendGridMessage> messageCollector,
            ILogger log)
        {
            log.LogInformation($"Sending email to {input.Item2}");
            var message = new SendGridMessage();

            message.AddTo(input.Item2);
            message.AddContent("text/html", $"Your ADX export job is finished. You can download you export file at {input.Item1}");
            message.SetFrom("*****@*****.**");
            message.SetSubject("ADX Export Completed!");

            await messageCollector.AddAsync(message);
        }
Ejemplo n.º 26
0
        public async Task SendEmail(string email, string subject, string message, string toUsername)
        {
            var client = new SendGridClient(_optionsEmailSettings.Value.SendGridApiKey);
            var msg    = new SendGridMessage();

            msg.SetFrom(new EmailAddress(_optionsEmailSettings.Value.SenderEmailAddress, "damienbod"));
            msg.AddTo(new EmailAddress(email, toUsername));
            msg.SetSubject(subject);
            msg.AddContent(MimeType.Text, message);
            //msg.AddContent(MimeType.Html, message);

            msg.SetReplyTo(new EmailAddress(_optionsEmailSettings.Value.SenderEmailAddress, "damienbod"));

            var response = await client.SendEmailAsync(msg);
        }
Ejemplo n.º 27
0
        public SendGridMessage CreateActivationMessage(UpdaterOrchestratorData activationData)
        {
            SendGridMessage message = new SendGridMessage()
            {
                Subject = $"Ticker informator activation"
            };

            message.From = _sender;
            message.AddTo(activationData.SubmitInfo.Email);

            string confirmationUri = GetConfirmationUri(activationData);

            message.AddContent("text/html", $"Activate: {GetConfirmationUri(activationData)}");
            return(message);
        }
Ejemplo n.º 28
0
        public static SendGridMessage Run([QueueTrigger("newContactMessage", Connection = "AzureWebJobsStorage")] ContactMessage contactMessage, ILogger log)
        {
            // We will have to find a way to get SendGrid to use Azure Key Vault, this template won't work.
            log.LogInformation($"C# Queue trigger function processed order: {contactMessage.Name}");


            SendGridMessage message = new SendGridMessage()
            {
                Subject = $"Contact from my Website!"
            };

            log.LogInformation($"C# Key: {message.Headers}");
            message.AddContent("text/plain", $"From: {contactMessage.Name} {Environment.NewLine}Email: {contactMessage.Email} {Environment.NewLine}Subject: {contactMessage.Subject} {Environment.NewLine}Comment: {contactMessage.Comment}");
            return(message);
        }
Ejemplo n.º 29
0
        public static void Run(
            [QueueTrigger("sendappointmentreminderqueue", Connection = "SendAppointmentReminderQueueConnectionString")] string sendAppointmentReminderItem,
            [SendGrid(ApiKey = "SendGridApiKey")] out SendGridMessage notificationEmail,
            ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {sendAppointmentReminderItem}");

            var notificationData = JsonConvert.DeserializeObject <AppointmentReminderMessage>(sendAppointmentReminderItem);

            notificationEmail = new SendGridMessage();
            notificationEmail.AddTo(notificationData.Email);
            notificationEmail.SetFrom(new EmailAddress("*****@*****.**", "Recruiter"));
            notificationEmail.SetSubject(notificationData.Subject);
            notificationEmail.AddContent("text/html", notificationData.Content);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Send a single simple email
        /// </summary>
        /// <param name="from">An email object that may contain the recipient’s name, but must always contain the sender’s email.</param>
        /// <param name="to">An email object that may contain the recipient’s name, but must always contain the recipient’s email.</param>
        /// <param name="subject">The subject of your email. This may be overridden by SetGlobalSubject().</param>
        /// <param name="plainTextContent">The text/plain content of the email body.</param>
        /// <param name="htmlContent">The text/html content of the email body.</param>
        /// <returns>A SendGridMessage object.</returns>
        public static SendGridMessage CreateSingleEmail(
            EmailAddress from,
            EmailAddress to,
            string subject,
            string plainTextContent,
            string htmlContent)
        {
            var msg = new SendGridMessage();

            msg.SetFrom(from);
            msg.SetSubject(subject);
            if (plainTextContent != null && plainTextContent != string.Empty)
            {
                msg.AddContent(MimeType.Text, plainTextContent);
            }

            if (htmlContent != null && htmlContent != string.Empty)
            {
                msg.AddContent(MimeType.Html, htmlContent);
            }

            msg.AddTo(to);
            return(msg);
        }