private void StartGmailClient() { string userName = ConfigurationManager.AppSettings["GMAIL_USERNAME"]; string userPwd = ConfigurationManager.AppSettings["GMAIL_USERPWD"]; if ((null == userName) || (null == userPwd)) { GmailClient = null; return; } ImapAccountInfo imapAccount = new ImapAccountInfo(); imapAccount.UserName = userName; imapAccount.UserPwd = userPwd; imapAccount.Provider = ImapProvider.GMail; SmtpAccountInfo smtpAccount = new SmtpAccountInfo(); smtpAccount.UserName = userName; smtpAccount.UserPwd = userPwd; smtpAccount.Provider = SmtpProvider.GMail; GmailClient = new MailClient(imapAccount, smtpAccount); }
/// This method creates a mail client that connects to a well-defined IMAP server and SMTP server. public MailClient(ImapAccountInfo ImapAccount, SmtpAccountInfo SmtpAccount) { imapClient = ImapAccount.Provider.InitClient(ImapAccount); smtpClient = SmtpAccount.Provider.InitClient(SmtpAccount); }
public SmtpClient InitClient(SmtpAccountInfo account) { SmtpClient smtpClient = new SmtpClient(account.Provider.Host); smtpClient.Port = account.Provider.Port; smtpClient.EnableSsl = account.Provider.EnableSsl; smtpClient.Credentials = new System.Net.NetworkCredential(account.UserName, account.UserPwd); return smtpClient; }