Exemplo n.º 1
0
        static Task <Message> ReadEmailAsync(ImapClient client, UniqueId uid, CancellationToken token)
        {
            return(Task.Run <Message>(() =>
            {
                Message message = new Message();

                MimeKit.MimeMessage newEmail = client.Inbox.GetMessage(uid);

                message.SentTime = (ulong)newEmail.Date.ToUnixTimeSeconds();

                MimeKit.MailboxAddress fromAdress = newEmail.From.Mailboxes.FirstOrDefault();
                message.EMail = fromAdress.Address;

                string content = "KEIN INHALT";
                if (newEmail.TextBody != null && newEmail.TextBody.Length > 5)
                {
                    content = newEmail.TextBody;
                }

                message.Content = content;

                message.Type = (ushort)MessageType.RecievedFromEmail;

                token.ThrowIfCancellationRequested();

                return message;
            }));
        }
Exemplo n.º 2
0
 private bool CheckMailAddress(MimeKit.MailboxAddress address, string addressRegex, string nameRegex)
 {
     return
         (address != null &&
          (!string.IsNullOrEmpty(address.Address) && !string.IsNullOrWhiteSpace(addressRegex) && Regex.IsMatch(address.Address, addressRegex)) ||
          (!string.IsNullOrEmpty(address.Name) && !string.IsNullOrWhiteSpace(nameRegex) && Regex.IsMatch(address.Name, nameRegex)));
 }
            GetDeliveryStatusNotifications(MimeKit.MimeMessage message, MimeKit.MailboxAddress mailbox)
            {
                //if (/* some criteria for deciding whether to get DSN's... */)
                return(MailKit.DeliveryStatusNotification.Delay |
                       MailKit.DeliveryStatusNotification.Failure |
                       MailKit.DeliveryStatusNotification.Success);

                // return null;
            }
Exemplo n.º 4
0
        /// <summary>
        /// 通过默认邮箱发送邮件
        /// </summary>
        /// <param name="subject">主题</param>
        /// <param name="htmlBody">HTML邮件体</param>
        /// <param name="toName">接收名称</param>
        /// <param name="toAddress">接收邮箱</param>
        public static void Send(string subject, string htmlBody, string toName, string toAddress)
        {
            // Mailbox Authorization Code: lmiuqpvhlnmebcfe

            // MailKit / MimeKit
            var message     = new MimeKit.MimeMessage();
            var defaultFrom = new MimeKit.MailboxAddress("Wagsn", "*****@*****.**");

            message.From.Add(defaultFrom);
            //message.To.Add(new MimeKit.MailboxAddress("2464", "*****@*****.**"));
            message.To.Add(new MimeKit.MailboxAddress(toName, toAddress));

            //message.Subject = "星期天去哪里玩?";
            message.Subject = subject;
            var bodyBuilder = new MimeKit.BodyBuilder();

            //bodyBuilder.HtmlBody = @"<h1>计划</h1><p>我想去故宫玩,如何</p>";
            //bodyBuilder.TextBody = "";
            bodyBuilder.HtmlBody = htmlBody;
            message.Body         = bodyBuilder.ToMessageBody();
            //message.Body = new TextPart("计划") { Text = "我想去故宫玩,如何" };

            using (var client2 = new MailKit.Net.Smtp.SmtpClient())
            {
                // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
                client2.ServerCertificateValidationCallback = (s, c, h, e) => true;

                client2.Connect("smtp.qq.com", 587, false);

                // Note: since we don't have an OAuth2 token, disable
                // the XOAUTH2 authentication mechanism.
                client2.AuthenticationMechanisms.Remove("XOAUTH2");

                // Note: only needed if the SMTP server requires authentication
                client2.Authenticate("*****@*****.**", "lmiuqpvhlnmebcfe");

                client2.Send(message);
                client2.Disconnect(true);
            }
        }
Exemplo n.º 5
0
 static MailAddress ConvertToMailAddress(MimeKit.MailboxAddress address)
 {
     return(new MailAddress(address.Address, address.Name ?? string.Empty, address.Encoding ?? Encoding.UTF8));
 }