private void btnLogin_Click(object sender, System.EventArgs e)
        {
            if (imap.Active)
            {
                return;
            }

            oAuth.AuthUrl      = "https://accounts.google.com/o/oauth2/auth";
            oAuth.TokenUrl     = "https://accounts.google.com/o/oauth2/token";
            oAuth.RedirectUrl  = "http://localhost";
            oAuth.ClientID     = "421475025220-6khpgoldbdsi60fegvjdqk2bk4v19ss2.apps.googleusercontent.com";
            oAuth.ClientSecret = "_4HJyAVUmH_iVrPB8pOJXjR1";
            oAuth.Scope        = "https://mail.google.com/";

            imap.Server = "imap.gmail.com";
            imap.Port   = 993;
            imap.UseTls = ClientTlsMode.Implicit;

            imap.UserName = edtUser.Text;

            imap.Authorization = oAuth.GetAuthorization();

            imap.Open();

            FillFolderList();
        }
示例#2
0
        private void btnSend_Click(object sender, System.EventArgs e)
        {
            if (smtp1.Active)
            {
                return;
            }

            oAuth1.AuthUrl     = "https://accounts.google.com/o/oauth2/auth";
            oAuth1.TokenUrl    = "https://accounts.google.com/o/oauth2/token";
            oAuth1.RedirectUrl = "http://localhost";

            //You need to specify both Client ID and Client Secret of your Google API Project.
            oAuth1.ClientID     = "421475025220-6khpgoldbdsi60fegvjdqk2bk4v19ss2.apps.googleusercontent.com";
            oAuth1.ClientSecret = "_4HJyAVUmH_iVrPB8pOJXjR1";

            oAuth1.Scope = "https://mail.google.com/";

            smtp1.Server = "smtp.gmail.com";
            smtp1.Port   = 587;
            smtp1.UseTls = ClientTlsMode.Explicit;

            smtp1.UserName = edtFrom.Text;

            smtp1.Authorization = oAuth1.GetAuthorization();

            smtp1.Open();
            try {
                mailMessage1.BuildMessage(memBody.Text, "");
                mailMessage1.From.FullAddress      = edtFrom.Text;
                mailMessage1.ToList.EmailAddresses = edtTo.Text;
                mailMessage1.Subject = edtSubject.Text;

                smtp1.Send(mailMessage1);

                MessageBox.Show("The message was sent successfully.");
            }
            finally {
                smtp1.Close();
            }
        }