Beispiel #1
0
        /// <summary>
        /// Tira um screenshot do Scorecard, enviando para o email do jogador
        /// da propriedade JogadorAEnviarPrint.
        /// </summary>
        private async Task TirarPrint()
        {
            ActivityIndicatorTool.ExecutarRoda();

            //Tirar screenshot.
            byte[] screenshot = await _screenshotService.TirarScreenshotAsync();

            //Guardar screenshot como anexo do email.
            MimeKit.AttachmentCollection attachments = new MimeKit.AttachmentCollection();
            attachments.Add("ScorecardPNG,", screenshot, ContentType.Parse("image/png"));

            //Enviar Email.
            try
            {
                await _emailService.EnviarEmail(emailDestino : JogadorAEnviarPrint.Email, assunto : "IT4ClubCar Game Results", mensagemConteudo : "Like you asked :)", attachments : attachments);

                await base.NavigationService.SairDeScorecard();
            }
            catch (SaslException e)
            {
                await base.DialogService.MostrarMensagem("Error while sending the email. Please try again later");
            }
            catch (AuthenticationException e)
            {
                await base.DialogService.MostrarMensagem("Error while sending the email. Please try again later");
            }

            ActivityIndicatorTool.PararRoda();
        }
Beispiel #2
0
        private MimeMessage BuildMessage(Dictionary <string, string> tos,
                                         Dictionary <string, string> ccs,
                                         Dictionary <string, string> bccs,
                                         string subject,
                                         string textBody,
                                         string htmlBody,
                                         AttachmentCollection attachments)
        {
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress(_emailSettings.SenderName, _emailSettings.SenderEmail));

            foreach (var to in tos)
            {
                message.To.Add(new MailboxAddress(to.Value, to.Key));
            }

            foreach (var cc in ccs)
            {
                message.Cc.Add(new MailboxAddress(cc.Value, cc.Key));
            }

            foreach (var bcc in bccs)
            {
                message.Bcc.Add(new MailboxAddress(bcc.Value, bcc.Key));
            }

            message.Subject = subject;

            var bodyBuilder = new BodyBuilder
            {
                HtmlBody = htmlBody,
                TextBody = textBody
            };

            foreach (var attachment in attachments)
            {
                bodyBuilder.Attachments.Add(attachment);
            }

            message.Body = bodyBuilder.ToMessageBody();

            message.MessageId =
                $"{string.Join(';', tos.Keys)};{new Random().Next(111111111, 999999999)}".Sha1();

            return(message);
        }
Beispiel #3
0
        private AttachmentCollection BuildAttachmentCollection(List <Attachment> attachments)
        {
            var attachmentCollection = new AttachmentCollection();

            foreach (var attachment in attachments)
            {
                var mimePart = new MimePart(attachment.Type, attachment.SubType)
                {
                    Content                 = new MimeContent(attachment.Content, ContentEncoding.Default),
                    ContentDisposition      = new ContentDisposition(ContentDisposition.Attachment),
                    ContentTransferEncoding = ContentEncoding.Base64,
                    FileName                = attachment.Name
                };
                attachmentCollection.Add(mimePart);
            }

            return(attachmentCollection);
        }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeKit.BodyBuilder"/> class.
 /// </summary>
 /// <remarks>
 /// Creates a new <see cref="BodyBuilder"/>.
 /// </remarks>
 public BodyBuilder()
 {
     LinkedResources = new AttachmentCollection(true);
     Attachments     = new AttachmentCollection();
 }
        static internal bool Send(EmailConfig config, InternetAddressList recipientsTo, InternetAddressList recipientsCc, InternetAddressList recipientsBcc, string subject, bool isHtml, string body, MimeKit.AttachmentCollection attachments)
        {
            if ((recipientsTo == null || recipientsTo.Count == 0) && (recipientsCc == null || recipientsCc.Count == 0) && (recipientsBcc == null || recipientsBcc.Count == 0))
            {
                return(false);
            }

            MimeMessage message     = new MimeMessage();
            BodyBuilder bodyBuilder = new BodyBuilder();

            MailKit.Net.Smtp.SmtpClient smtp = new MailKit.Net.Smtp.SmtpClient();

            // Set the recipients
            message.From.Add(new MailboxAddress(config.DisplayName, config.Address));
            message.To.AddRange(recipientsTo ?? new InternetAddressList());
            message.Cc.AddRange(recipientsCc ?? new InternetAddressList());
            message.Bcc.AddRange(recipientsBcc ?? new InternetAddressList());

            // Set the properties and establish the Smtp server connection
            smtp.Timeout = config.SmtpTimeout;
            try
            {
                smtp.Connect(config.SmtpServer, config.SmtpPort, GetSslOptionsEnumValue(config.SmtpSslOptions));
            }
            catch (Exception ex)
            {
                Error.ProcessError(ex, "Error al conectar al servidor SMTP.");
                return(false);
            }
            string decryptedPassword = string.Empty;

            if (!Encrypt.StringCipher.Decrypt(config.SmtpPassword, Constants.PublicEncryptionPassword, ref decryptedPassword))
            {
                MessageBox.Show("La contraseña de e-mail (SMTP) especificada es incorrecta.", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }
            try
            {
                smtp.Authenticate(new System.Net.NetworkCredential(config.SmtpUserName, decryptedPassword));
            }
            catch (Exception)
            {
                MessageBox.Show("Error al iniciar sesión en el servidor SMTP.", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            // Set the content
            message.Subject = subject ?? string.Empty;
            if (isHtml)
            {
                bodyBuilder.HtmlBody = body;
            }
            else
            {
                bodyBuilder.TextBody = body;
            }

            // Set the attachments
            if (attachments != null)
            {
                foreach (MimeEntity attachment in attachments)
                {
                    bodyBuilder.Attachments.Add(attachment);
                }
            }

            // Set the body
            message.Body = bodyBuilder.ToMessageBody();

            // Send the message
            try
            {
                smtp.Send(message);
            }
            catch (Exception)
            {
                MessageBox.Show("Error al enviar el e-mail.", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            // Closes the Smtp server connection
            try
            {
                smtp.Disconnect(true);
            }
            catch (Exception)
            {
                MessageBox.Show("Error al desconectar al servidor SMTP.", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            return(true);
        }
        static internal bool Send(EmailConfig config, string recipientToDisplayName, string recipientToAddress, string recipientCcDisplayName, string recipientCcAddress, string recipientBccDisplayName, string recipientBccAddress, string subject, bool isHtml, string body, MimeKit.AttachmentCollection attachments)
        {
            InternetAddressList recipientsTo  = new InternetAddressList();
            InternetAddressList recipientsCc  = new InternetAddressList();
            InternetAddressList recipientsBcc = new InternetAddressList();

            if (!string.IsNullOrWhiteSpace(recipientToAddress))
            {
                recipientsTo.Add(new MailboxAddress(recipientToDisplayName, recipientToAddress));
            }
            if (!string.IsNullOrWhiteSpace(recipientCcAddress))
            {
                recipientsCc.Add(new MailboxAddress(recipientCcDisplayName, recipientCcAddress));
            }
            if (!string.IsNullOrWhiteSpace(recipientBccAddress))
            {
                recipientsBcc.Add(new MailboxAddress(recipientBccDisplayName, recipientBccAddress));
            }

            return(Send(config, recipientsTo, recipientsCc, recipientsBcc, subject, isHtml, body, attachments));
        }