Exemple #1
0
        //Function to send email using  sendgrid
        public static bool SendEmail(string from_email, string to_email, string email_subject, string message_body, string smtp_email, string smtp_pass, string display_name, string smtp_host, int smtp_port)
        {
            AppFunctions functions = new AppFunctions();

            try
            {
                var apiKey           = "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";
                var client           = new SendGridClient(apiKey);
                var from             = new EmailAddress(from_email, display_name);
                var subject          = email_subject;
                var to               = new EmailAddress(to_email, to_email.Split("@")[0]);
                var plainTextContent = functions.StripHTML(message_body);
                var htmlContent      = message_body;
                var msg              = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
                var response         = client.SendEmailAsync(msg);

                return(true);
            }
            catch (Exception ex)
            {
                //TODO log error
                Console.WriteLine(ex);
                return(false);
            }
        }