Example #1
0
        static void Main(string[] args)
        {
            GoogleCredential credential;

            using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
            {
                credential = GoogleCredential.FromStream(stream)
                             .CreateScoped(Scopes);
            }

            // Create Google Sheets API service.
            service = new SheetsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Create Mail Service
            mailService = new MailService();

            var promoter = new Promoter
            {
                Name         = "Adam",
                EmailAddress = "*****@*****.**"
            };

            mailService.SendMail(promoter);

            //ReadEntries();
            Console.WriteLine("////// FINISHED ///////");
            Console.ReadKey();
        }
Example #2
0
        public void SendMail(Promoter promoter)
        {
            Console.WriteLine($"Sending mail to ${promoter.Name} at ${promoter.EmailAddress}");

            try
            {
                using (var message = new MailMessage())
                {
                    message.To.Add(new MailAddress(promoter.EmailAddress, promoter.Name));
                    message.From       = new MailAddress(AppSettings.EmailAddres, "Hard Fact");
                    message.Subject    = "Subject";
                    message.Body       = "Body";
                    message.IsBodyHtml = true;

                    using (var client = new SmtpClient("smtp.gmail.com"))
                    {
                        client.Port        = 587;
                        client.Credentials = new NetworkCredential(AppSettings.EmailAddres, AppSettings.EmailPassword);
                        client.EnableSsl   = true;
                        client.Send(message);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error sending mail to {promoter.EmailAddress}. {e}");
            }
        }