public Email(Message message, MessageLabel label)
        {
            GmailService service        = MailService.Service;
            MessagePart  messagePayload = GetEmailDetails(message);

            foreach (var payloadHeader in messagePayload.Headers)
            {
                if (payloadHeader.Name == "Message-ID")
                {
                    emailId = payloadHeader.Value;
                }
                else if (payloadHeader.Name == "Subject")
                {
                    emailSubject = payloadHeader.Value;
                }
                else if (payloadHeader.Name == "From")
                {
                    sender = payloadHeader.Value;
                }
                else if (payloadHeader.Name == "To")
                {
                    receiver = payloadHeader.Value;
                }
                else if (payloadHeader.Name == "Date")
                {
                    emailDate = payloadHeader.Value;
                }
            }
            emailBody     = GetEmailBody(messagePayload.Parts, "plain");
            emailBodyHTML = GetEmailBody(messagePayload.Parts, "html");
            emailLabel    = label;
        }
        // Select the control button panel corresponding to the message label.
        private void DisplayMessageControlButtons(MessageLabel label)
        {
            inboxControlPanel.Visible = false;
            sentControlPanel.Visible  = false;
            draftControlPanel.Visible = false;
            spamControlPanel.Visible  = false;
            trashControlPanel.Visible = false;

            if (label == MessageLabel.INBOX)
            {
                inboxControlPanel.Visible = true;
            }
            else if (label == MessageLabel.SENT)
            {
                sentControlPanel.Visible = true;
            }
            else if (label == MessageLabel.DRAFT)
            {
                draftControlPanel.Visible = true;
            }
            else if (label == MessageLabel.SPAM)
            {
                spamControlPanel.Visible = true;
            }
            else if (label == MessageLabel.TRASH)
            {
                trashControlPanel.Visible = true;
            }
        }
Пример #3
0
        private void LoginBtn_Click(object sender, EventArgs e)
        {
            if (EmailTxt.Text == "" || PasswordTxt.Text == "")
            {
                MessageBox.Show("Please fill the text areas!", "Error");
                return;
            }
            user.Email    = EmailTxt.Text;
            user.Password = PasswordTxt.Text;
            user.Serialize();
            MessageLabel main = new MessageLabel(user);

            Hide();
            main.ShowDialog();
            Close();
        }
        // Send request for retrieving all emails of the given label with an optional search parameter.
        public static IList <Message> ListMessages(GmailService service, String userId, MessageLabel label, string query = null)
        {
            List <Message> result = new List <Message>();

            UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List(userId);
            request.LabelIds = label.ToString();
            if (query != null)
            {
                request.Q = query;
            }

            do
            {
                try
                {
                    ListMessagesResponse response = request.Execute();
                    result.AddRange(response.Messages);
                }
                catch (Exception e)
                {
                    Console.WriteLine("An error occurred: " + e.Message);
                }
            } while (!String.IsNullOrEmpty(request.PageToken));

            return(result);
        }