Exemple #1
0
        public static void SendEmail(YanapayEmail email, GmailService service)
        {
            var mailMessage = new System.Net.Mail.MailMessage();

            mailMessage.From = new System.Net.Mail.MailAddress(email.FromAddress);
            mailMessage.To.Add(email.ToRecipients);
            mailMessage.ReplyToList.Add(email.FromAddress);
            mailMessage.Subject         = email.Subject;
            mailMessage.Body            = email.Body;
            mailMessage.IsBodyHtml      = email.IsHtml;
            mailMessage.BodyEncoding    = System.Text.Encoding.GetEncoding("ISO-8859-1");
            mailMessage.HeadersEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
            mailMessage.SubjectEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");

            var mimeMessage = MimeKit.MimeMessage.CreateFromMailMessage(mailMessage);

            var gmailMessage = new Google.Apis.Gmail.v1.Data.Message
            {
                Raw = Encode(mimeMessage.ToString())
            };

            Google.Apis.Gmail.v1.UsersResource.MessagesResource.SendRequest request = service.Users.Messages.Send(gmailMessage, "me");

            request.Execute();
        }
Exemple #2
0
        public static void ConectarAPI(YanapayEmail email)
        {
            UserCredential credential;

            using (var stream =
                       new FileStream("C:/inetpub/wwwroot/TableSoftEmail/credentials.json", FileMode.Open, FileAccess.Read))
            {
                // The file token.json stores the user's access and refresh tokens, and is created
                // automatically when the authorization flow completes for the first time.
                string credPath = "C:/pixies/token.json";
                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Gmail API service.
            var service = new GmailService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName,
            });

            // Define parameters of request.
            UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me");

            SendEmail(email, service);
        }
Exemple #3
0
 public bool EnviarCorreo(YanapayEmail email)
 {
     try
     {
         GmailAPI.ConectarAPI(email);
         return(true);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message.ToString());
         return(false);
     }
 }
Exemple #4
0
 public string EnviarCorreoString(string subject, string body, string recipient)
 {
     try
     {
         YanapayEmail email = new YanapayEmail()
         {
             FromAddress  = "*****@*****.**",
             ToRecipients = recipient,
             Subject      = subject,
             Body         = body,
             IsHtml       = false
         };
         GmailAPI.ConectarAPI(email);
         return("enviado");
     }
     catch (Exception ex)
     {
         return(ex.Message.ToString());
     }
 }