private void btnGetMail_Click(object sender, EventArgs e) { txtTrangthai.Text = "Đang Get Mail...."; mailbox = String.Format("{0}\\inbox", curpath); try { oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); for (int i = 0; i < 5; i++) { MailInfo info = infos[i]; /* Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", * info.Index, info.Size, info.UIDL);*/ // Download email from GMail IMAP4 server Mail oMail = oClient.GetMail(info); /* Console.WriteLine("From: {0}", oMail.From.ToString()); * Console.WriteLine("Subject: {0}\r\n", oMail.Subject); * Console.WriteLine("Body Text: {0}\r\n", oMail.TextBody); */ ListViewItem lstinfo = new ListViewItem(); lstinfo.Text = oMail.Subject; lstEmail.Items.Add(lstinfo); // Generate an email file name based on date time. System.DateTime d = System.DateTime.Now; System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("en-US"); string sdate = d.ToString("yyyyMMddHHmmss", cur); string fileName = String.Format("{0}\\{1}{2}{3}.eml", mailbox, sdate, d.Millisecond.ToString("d3"), i); // Save email to local disk oMail.SaveAs(fileName, true); // Mark email as deleted in GMail account. //oClient.Delete(info); oClient.MarkAsRead(info, true); } txtTrangthai.Text = "Get mail Thành Công..."; // Quit and pure emails marked as deleted from Gmail IMAP4 server. oClient.Quit(); } catch (Exception ep) { txtTrangthai.Text = ep.Message; } }
public void TestInterOp() { MailServer oServer = new MailServer("outlook.office365.com", "*****@*****.**", "Password!", ServerProtocol.Imap4); MailClient oClient = new MailClient("TryIt"); oServer.Port = 993; oServer.SSLConnection = true; oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", info.Index, info.Size, info.UIDL); // Receive email from IMAP4 server Mail oMail = oClient.GetMail(info); Console.WriteLine("From: {0}", oMail.From.ToString()); Console.WriteLine("Subject: {0}\r\n", oMail.Subject); } }
public void WantedInbox(string emailName) { Show(); Text = emailName; RegistryKey currentLoginKey = emailLoginsKey.OpenSubKey(emailName, true); loginInfo = new LoginInfo() { email = emailName, portSMTP = currentLoginKey.GetValue("portSMTP").ToString(), portIMAP = currentLoginKey.GetValue("portIMAP").ToString(), serverSMTP = currentLoginKey.GetValue("serverSMTP").ToString(), serverIMAP = currentLoginKey.GetValue("serverIMAP").ToString(), contracena = Program.DecryptStringFromBytes((byte[])currentLoginKey.GetValue("contracena", RegistryValueKind.Binary), Encoding.ASCII.GetBytes("1234567890123456"), Encoding.ASCII.GetBytes("1234567890123456")) }; mailServer = new MailServer(loginInfo.serverIMAP, loginInfo.email, loginInfo.contracena, ServerProtocol.Imap4) { SSLConnection = true, Port = Int32.Parse(loginInfo.portIMAP) }; mailClient = new MailClient("TryIt"); try { mailClient.Connect(mailServer); } catch (Exception ex) { Text = "rozłączono"; } getFoldersDisplayed(); }
public void Connect(string server, string User, string pass, int port, bool useSSl) { oServer = new MailServer(server, User, pass, useSSl, ServerAuthType.AuthLogin, mprotocol == MailProtocol.pop3?ServerProtocol.Pop3 : ServerProtocol.Imap4); oClient = new MailClient("TryIt"); oServer.Port = port; oClient.Connect(oServer); }
private void Login_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrWhiteSpace(tbEmail.Text) || String.IsNullOrWhiteSpace(tbPassword.Password)) { MessageBox.Show("Enter Login/Password"); } else { server = new MailServer( "imap.gmail.com", tbEmail.Text, tbPassword.Password, ServerProtocol.Imap4) { SSLConnection = true, Port = 993 }; try { client.Connect(server); if (client.Connected) { Close(); } else { MessageBox.Show("Error. Invalid e-mail/password"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void Form1_Load(object sender, EventArgs e) { string curpath = Directory.GetCurrentDirectory(); string mailbox = String.Format("{0}\\inbox", curpath); // If the folder is not existed, create it. if (!Directory.Exists(mailbox)) { Directory.CreateDirectory(mailbox); } MailServer oServer = new MailServer("pop.gmail.com", "*****@*****.**", "jarvis99", ServerProtocol.Pop3); MailClient oClient = new MailClient("TryIt"); // If your POP3 server requires SSL connection, // Please add the following codes: oServer.SSLConnection = true; oServer.Port = 995; MessageBox.Show("Connection opened"); try { oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); MessageBox.Show("Mail information received"); MessageBox.Show(infos.ToString()); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; //Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", // info.Index, info.Size, info.UIDL); // Receive email from POP3 server Mail oMail = oClient.GetMail(info); MessageBox.Show("From: " + oMail.From.ToString()); MessageBox.Show("Subject: \r\n" + oMail.Subject); MessageBox.Show("inside1"); // Generate an email file name based on date time. System.DateTime d = System.DateTime.Now; System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("en-US"); string sdate = d.ToString("yyyyMMddHHmmss", cur); string fileName = String.Format("{0}\\{1}{2}{3}.eml", mailbox, sdate, d.Millisecond.ToString("d3"), i); MessageBox.Show("inside4"); // Save email to local disk oMail.SaveAs(fileName, true); // Mark email as deleted from POP3 server. oClient.Delete(info); } // Quit and pure emails marked as deleted from POP3 server. oClient.Quit(); } catch (Exception ep) { MessageBox.Show("error" + ep.Message); } }
void OdznaczJeNaSerwerze() { foreach (string emailName in emailLoginsKey.GetSubKeyNames()) { RegistryKey currentLoginKey = emailLoginsKey.OpenSubKey(emailName, true); LoginInfo loginInfo = new LoginInfo() { email = emailName, portSMTP = currentLoginKey.GetValue("portSMTP").ToString(), portIMAP = currentLoginKey.GetValue("portIMAP").ToString(), serverSMTP = currentLoginKey.GetValue("serverSMTP").ToString(), serverIMAP = currentLoginKey.GetValue("serverIMAP").ToString(), contracena = Program.DecryptStringFromBytes((byte[])currentLoginKey.GetValue("contracena", RegistryValueKind.Binary), Encoding.ASCII.GetBytes("1234567890123456"), Encoding.ASCII.GetBytes("1234567890123456")) }; MailServer mailServer = new MailServer(loginInfo.serverIMAP, loginInfo.email, loginInfo.contracena, ServerProtocol.Imap4) { SSLConnection = true, Port = Int32.Parse(loginInfo.portIMAP) }; MailClient mailClient = new MailClient("TryIt"); mailClient.Connect(mailServer); MailInfo[] infos = mailClient.GetMailInfos(); foreach (MailInfo mailInfo in infos) { foreach (UnreadMail unreadMailTemp in unreadMails) { if (unreadMailTemp.shouldMarkAsRead && mailInfo.UIDL == unreadMailTemp.idUIDL && unreadMailTemp.emailLogin == emailName) { mailClient.MarkAsRead(mailInfo, true); } } } } }
private void BtnUpdateMessages_Click(object sender, RoutedEventArgs e) { listBoxMessages.Items.Clear(); MailServer server = new MailServer( textServer.Text, textEmail.Text, textPassword.Password, EAGetMail.ServerProtocol.Imap4) { SSLConnection = true, Port = 993 }; MailClient client = new MailClient("TryIt"); try { client.Connect(server); var messages = client.GetMailInfos(); foreach (var m in messages) { Mail message = client.GetMail(m); listBoxMessages.Items.Add($"From: {message.From}\n\n\t{message.Subject}\n"); } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } }
public DataTable CaptureMessages() { MailClient oClient = new MailClient("TryIt"); MailServer oServer = CreateMailServer(); oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); DataTable emailTable = new DataTable(); emailTable.Columns.Add("From", typeof(string)); emailTable.Columns.Add("Body", typeof(string)); string mailBox = CreateInbox(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; Mail oMail = oClient.GetMail(info); System.DateTime d = System.DateTime.Now; System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("en-US"); string sDate = d.ToString("yyyyMMddHHmmss", cur); string fileName = String.Format("{0}\\{1}{2}{3}.eml", mailBox, sDate, d.Millisecond.ToString("d3"), i); oMail.SaveAs(fileName, true); string from = oMail.From.ToString(); string displayFrom = from.Substring(1, 10); emailTable.Rows.Add(displayFrom, oMail.TextBody); } return emailTable; }
static void Main(string[] args) { // Create a folder named "inbox" under current directory string curpath = Directory.GetCurrentDirectory(); string mailbox = String.Format("{0}\\inbox", curpath); // If the folder is not existed, create it. if (!Directory.Exists(mailbox)) { Directory.CreateDirectory(mailbox); } MailServer oServer = new MailServer("pop3.live.com", "email", "pass", ServerProtocol.Pop3); MailClient oClient = new MailClient("TryIt"); // Enable SSL connection. oServer.SSLConnection = true; // Set 995 SSL port oServer.Port = 995; try { oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", info.Index, info.Size, info.UIDL); // Receive email from POP3 server Mail oMail = oClient.GetMail(info); Console.WriteLine("From: {0}", oMail.From.ToString()); Console.WriteLine("Subject: {0}\r\n", oMail.Subject); // Generate an email file name based on date time. System.DateTime d = System.DateTime.Now; System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("pt-PT"); string sdate = d.ToString("yyyyMMddHHmmss", cur); string fileName = String.Format("{0}\\{1}{2}{3}.eml", mailbox, sdate, d.Millisecond.ToString("d3"), i); // Save email to local disk oMail.SaveAs(fileName, true); Console.Write("Novo email\n"); Console.Write(""); // Mark email as deleted from POP3 server. //oClient.Delete(info); } oClient.Quit(); } catch (Exception ep) { Console.WriteLine(ep.Message); } }
/// <summary> /// 获取邮件数据信息,并限定条件 /// </summary> /// <param name="startDate">晚于指定的接收日期的邮件</param> /// <param name="endDate">早于指定接收日期的邮件</param> /// <param name="titleKeywords">邮件标题中的关键词</param> public List <EmailDataInfo> GetMailDataInfos(DateTime?startDate = null, DateTime?endDate = null, String[] titleKeywords = null) { List <EmailDataInfo> emailDataInfos = new List <EmailDataInfo>(); List <Mail> mails = new List <Mail>(); List <MailInfo> mailInfos = new List <MailInfo>(); MailServer oServer = new MailServer(MailServerAddress, this.User, this.Password, true, ServerAuthType.AuthLogin, ServerProtocol.Imap4); oServer.Port = 993; MailClient oClient = new MailClient(LicenseCode); try { oClient.Connect(oServer); String condition = "ALL"; if (startDate.HasValue) { String startDateStr = this.GetDateString(startDate.Value); condition += " SINCE " + startDateStr; } if (endDate.HasValue) { String endDateStr = this.GetDateString(endDate.Value); condition += " SENTBEFORE " + endDateStr; } //官网上提供的一系列关键词的条件都无效,暂时使用本地筛选的方法。 https://www.emailarchitect.net/eagetmail/sdk/ //if (!String.IsNullOrWhiteSpace(titleKeyword)) //{ // condition += $" KEYWORD {titleKeyword}"; //} MailInfo[] result = oClient.SearchMail(condition); mailInfos.AddRange(result); foreach (var info in mailInfos) { //先获取邮件头部信息,此处邮件的信息并不完整,后续需要使用 GetMail 获取完整的邮件信息 var headerMailData = oClient.GetMailHeader(info); var headerMail = new Mail(LicenseCode); headerMail.Load(headerMailData); if (this.AccordTitleKeywords(headerMail.Subject, titleKeywords)) { EmailDataInfo dataInfo = new EmailDataInfo(); this.BuildEmailDataInfo(dataInfo, headerMail, info); emailDataInfos.Add(dataInfo); } } } finally { oClient.Quit(); oClient.Close(); } return(emailDataInfos); }
static void Main(string[] args) { // Create a folder named "inbox" under current directory // to save the email retrie enter code here ved. string curpath = Directory.GetCurrentDirectory(); string mailbox = String.Format("{0}\\inbox", curpath); // If the folder is not existed, create it. if (!Directory.Exists(mailbox)) { Directory.CreateDirectory(mailbox); } // Gmail IMAP4 server is "imap.gmail.com" MailServer oServer = new MailServer("imap.gmail.com", "*****@*****.**", "yourpassword", ServerProtocol.Imap4); MailClient oClient = new MailClient("TryIt"); // Set SSL connection, oServer.SSLConnection = true; // Set 993 IMAP4 port oServer.Port = 993; try { oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", info.Index, info.Size, info.UIDL); // Download email from GMail IMAP4 server Mail oMail = oClient.GetMail(info); Console.WriteLine("From: {0}", oMail.From.ToString()); Console.WriteLine("Subject: {0}\r\n", oMail.Subject); // Generate an email file name based on date time. System.DateTime d = System.DateTime.Now; System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("en-US"); string sdate = d.ToString("yyyyMMddHHmmss", cur); string fileName = String.Format("{0}\\{1}{2}{3}.eml", mailbox, sdate, d.Millisecond.ToString("d3"), i); // Save email to local disk oMail.SaveAs(fileName, true); // Mark email as deleted in GMail account. oClient.Delete(info); } // Quit and purge emails marked as deleted from Gmail IMAP4 server. oClient.Quit(); } catch (Exception ep) { Console.WriteLine(ep.Message); } }
public Mail GetMailDetail(MailInfo mailInfo) { MailServer server = new MailServer("imap.gmail.com", eMailAddress, passWord, ServerProtocol.Imap4); MailClient client = new MailClient("TryIt"); server.SSLConnection = true; server.Port = 993; client.Connect(server); return(client.GetMail(mailInfo)); }
public void TestPopNew() { MailServer oServer = new MailServer("outlook.office365.com", "*****@*****.**", "Beam@Pass111", ServerProtocol.Pop3); MailClient oClient = new MailClient("TryIt"); oServer.Port = 995; oServer.SSLConnection = true; oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); }
public static void ConnectToGmailAccountAndGetOrUpdateMails() { // Gmail IMAP4 server is "imap.gmail.com" MailServer oServer = new MailServer("imap.gmail.com", "*****@*****.**", "maker2018", ServerProtocol.Imap4); MailClient oClient = new MailClient("TryIt"); // Set SSL connection, oServer.SSLConnection = true; // Set 993 IMAP4 port oServer.Port = 993; try { oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); lastMailsKnownNumber = infos.Length; //si le tableau des emails est vide telecharger tout les emails maintenant dans un tabelau et une liste if (listMails.Count == 0) { //mails = oClient.FetchMails(false); for (int i = 0; i < infos.Length; i++) { Mail tempMail = oClient.GetMail(infos[i]); //tempMail.Subject = tempMail.Subject.Replace("(Trial Version)", ""); tempMail.HtmlBody.Remove(0, 25); // tempMail.Tag =i; //tempMail.HtmlBody.Replace("</body></html>", ""); listMails.Add(oClient.GetMail(infos[i])); } } else // sinon , telecharger seulement les nouveau mails et les ajouter dans le tableau et la liste { for (int i = listMails.Count; i < infos.Length; i++) { //mails[i] = oClient.GetMail(infos[i]); Mail newMail = oClient.GetMail(infos[i]); //newMail.Subject =newMail.Subject.Replace("(Trial Version)", ""); newMail.HtmlBody.Remove(0, 25); //newMail.Tag = i; // newMail.HtmlBody.Replace("</body></html>", ""); listMails.Add(newMail); System.Console.WriteLine("New mail From=" + newMail.From + " Subject=" + newMail.Subject + " Body=" + newMail.TextBody); } } } catch (Exception e) { } }
public List <Mail> retrieveNewMailFromGmail(/*int userId*/ string adrMail, string password) { List <Mail> newMails = new List <Mail>(); try { // Gmail IMAP4 server is "imap.gmail.com" MailServer mailServer = new MailServer( "imap.gmail.com", adrMail, password, ServerProtocol.Imap4); // Enable SSL connection. mailServer.SSLConnection = true; mailServer.Port = 993; MailClient mailClient = new MailClient("TryIt"); mailClient.Connect(mailServer); // retrieve unread/new email only mailClient.GetMailInfosParam.Reset(); mailClient.GetMailInfosParam.GetMailInfosOptions = GetMailInfosOptionType.NewOnly; MailInfo[] infos = mailClient.GetMailInfos(); Console.WriteLine("Total {0} unread email(s)\r\n", infos.Length); // Receive email list from IMAP4 server for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", info.Index, info.Size, info.UIDL); //// Receive email from IMAP4 server Mail oMail = mailClient.GetMail(info); newMails.Add(oMail); // mark unread email as read, next time this email won't be retrieved again if (!info.Read) { mailClient.MarkAsRead(info, true); } } // Quit and expunge emails marked as deleted from IMAP4 server. mailClient.Quit(); Console.WriteLine("Completed!"); } catch (Exception ep) { Console.WriteLine(ep.Message); } return(newMails); }
private void login_Click(object sender, RoutedEventArgs e) { if (NameMail.Text != "" && textPassword.Password != "") { info_Send.Mail = NameMail.Text; info_Send.pasword = textPassword.Password; if (Gmail.IsChecked == true) { info_Send.emailClient = ConfigurationManager.AppSettings["gmail_server"]; info_Send.port = int.Parse(ConfigurationManager.AppSettings["gmail_port"]); info_Send.portmp = int.Parse(ConfigurationManager.AppSettings["gmail_portMp"]); info_Send.emailClientMp = ConfigurationManager.AppSettings["gmail_serverMp"]; } else if (ukrnet.IsChecked == true) { info_Send.emailClient = ConfigurationManager.AppSettings["ukr_server"]; info_Send.port = int.Parse(ConfigurationManager.AppSettings["ukr_port"]); info_Send.portmp = int.Parse(ConfigurationManager.AppSettings[" ukr_portMp"]); info_Send.emailClientMp = ConfigurationManager.AppSettings["ukr_serverMp"]; } Console.WriteLine("Login secsesful"); login.IsEnabled = false; MailServer server = new MailServer( info_Send.emailClientMp, info_Send.Mail, info_Send.pasword, ServerProtocol.Imap4) { SSLConnection = true, Port = info_Send.portmp }; client = new MailClient("TryIt"); // trial version try { client.Connect(server); foreach (var f in client.GetFolders()) { folderText.Items.Add(f.Name); } } catch (Exception) { throw; } } }
private void pictureBox2_Click(object sender, EventArgs e) { MailServer oServer = new MailServer("pop.gmail.com", "*****@*****.**", "nourbess", true, ServerAuthType.AuthLogin, ServerProtocol.Pop3); MailClient oClient = new MailClient("TryIt"); oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; // Receive email from POP3 server Mail oMail = oClient.GetMail(info); String[] substrings = oMail.TextBody.Split('\n'); String[] substrings2 = substrings[0].Split(':'); String[] substrings3 = substrings[1].Split(':'); String[] substrings4 = substrings[2].Split(':'); String[] substrings5 = substrings[3].Split(':'); String[] substrings6 = substrings[4].Split(':'); //FAX String[] substrings7 = substrings[5].Split(':'); //Responsable String[] substrings8 = substrings[6].Split(':'); // Console.WriteLine(substrings8[substrings8.Length - 1]); String[] X = substrings8[substrings8.Length - 1].Split(' '); Debug.WriteLine(X[0]); //Type d'intervention String[] substrings9 = substrings[7].Split(':'); //delai String[] substrings10 = substrings[8].Split(':'); //mail String[] substrings11 = substrings[9].Split(':'); //Reclamation String[] substrings12 = substrings[10].Split(':'); using (SqlConnection conn = Get_Connection()) { conn.Open(); String req = "INSERT INTO tickets(nom, prenom,raison_Sociale,contrat_Id,tel,type_Intervention,delai,mail,reclamation,date_deb) VALUES ('" + substrings2[substrings2.Length - 1] + "','" + substrings3[substrings3.Length - 1] + "','" + substrings4[substrings4.Length - 1] + "','" + substrings5[substrings5.Length - 1] + "','" + substrings6[substrings6.Length - 1] + "','" + substrings9[substrings9.Length - 1] + "','" + substrings10[substrings10.Length - 1] + "','" + substrings11[substrings11.Length - 1] + "','" + substrings12[substrings12.Length - 1] + "','" + oMail.SentDate + "')"; using (SqlCommand cmd = new SqlCommand(req, conn)) { cmd.ExecuteNonQuery(); } } } }
private void button1_Click(object sender, EventArgs e) { if (!Send.IsValidEmail(textBox1.Text)) { MessageBox.Show("Invalid email format! Please introduce email orrectly!", "Warning !"); return; } textBox3.Visible = true; textBox3.Text = string.Empty; try { MailServer oServer = new MailServer("pop.gmail.com", textBox1.Text, textBox2.Text, EAGetMail.ServerProtocol.Imap4); oServer.Port = 993; oServer.SSLConnection = true; MailClient oClient = new MailClient("TryIt"); oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); textBox3.Text += "Total "; textBox3.Text += infos.Length; textBox3.Text += " email(s)\r\n"; for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; textBox3.Text += info.Index; textBox3.Text += ". "; // Receive email from POP3 server Mail oMail = oClient.GetMail(info); textBox3.AppendText(Environment.NewLine); textBox3.Text += "\nFrom: "; textBox3.Text += oMail.From.ToString(); textBox3.AppendText(Environment.NewLine); textBox3.Text += "\nSubject: "; textBox3.Text += oMail.Subject; textBox3.Text += "\r\n"; } oClient.Quit(); } catch (Exception ep) { textBox3.Visible = false; MessageBox.Show("Email or password incorrect", "Warning!"); } }
public static void GetAndSaveToDatabaseMailInfo(string emailAddress, string accountPassword) { MailServer oServer = new MailServer("imap-mail.outlook.com", emailAddress, accountPassword, ServerProtocol.Imap4); MailClient oClient = new MailClient("TryIt"); oServer.SSLConnection = true; oServer.Port = 993; try { oClient.Connect(oServer); List <MailInfo> allMailInfos = oClient.GetMailInfos().ToList(); foreach (MailInfo item in allMailInfos) { Console.WriteLine(item.Index); using (SqlConnection con = new SqlConnection("Data Source=.\\sql2016; Initial Catalog=Outlook; Integrated Security=SSPI;")) { using (SqlCommand cmd = new SqlCommand("sp_insertMailInfo", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Deleted", SqlDbType.Bit).Value = item.Deleted; cmd.Parameters.Add("@Envelope", SqlDbType.VarChar).Value = item.Envelope; cmd.Parameters.Add("@EWSChangeKey", SqlDbType.VarChar).Value = item.EWSChangeKey; cmd.Parameters.Add("@EWSPublicFolder", SqlDbType.Bit).Value = item.EWSPublicFolder; cmd.Parameters.Add("@IMAP4MailFlags", SqlDbType.VarChar).Value = item.IMAP4MailFlags; cmd.Parameters.Add("@Index", SqlDbType.Int).Value = item.Index; cmd.Parameters.Add("@PostItem", SqlDbType.Bit).Value = item.PostItem; cmd.Parameters.Add("@Read", SqlDbType.Bit).Value = item.Read; cmd.Parameters.Add("@Size", SqlDbType.Int).Value = item.Size; cmd.Parameters.Add("@UIDL", SqlDbType.VarChar).Value = item.UIDL; con.Open(); cmd.ExecuteNonQuery(); } } } oClient.Quit(); } catch (Exception ep) { Console.WriteLine(ep.Message); } }
private void leerCorreos() { // Create a folder named "inbox" under current directory // to save the email retrieved. string curpath = Directory.GetCurrentDirectory(); string mailbox = String.Format("{0}\\inbox", curpath); // If the folder is not existed, create it. if (!Directory.Exists(mailbox)) { Directory.CreateDirectory(mailbox); } MailServer oServer = new MailServer("imap.gmail.com", "*****@*****.**", "correocs", ServerProtocol.Imap4); MailClient oClient = new MailClient("TryIt"); oServer.SSLConnection = true; oServer.Port = 993; try { string json; oClient.Connect(oServer); infos = oClient.GetMailInfos(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; Mail oMail = oClient.GetMail(info); if (!info.Read) { json = oMail.TextBody; Formu jsonObj = new Formu(); jsonObj = JsonConvert.DeserializeObject <Formu>(json); dgvSolicitudes.Rows[dgvSolicitudes.Rows.Add()].Cells[0].Value = (contador + 1).ToString(); dgvSolicitudes.Rows[contador].Cells[1].Value = jsonObj.NombreCompleto; dgvSolicitudes.Rows[contador].Cells[2].Value = oMail.ReceivedDate.ToShortDateString(); lista.Add(json); contador++; } } // Quit and purge emails marked as deleted from Gmail IMAP4 server. oClient.Quit(); Console.Read(); } catch (Exception ep) { Console.WriteLine(ep.Message); Console.Read(); } }
private void Button_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(EmailTextBox.Text) || string.IsNullOrEmpty(PasswordBox.Password)) { return; } MailServer server = new MailServer( "", EmailTextBox.Text, PasswordBox.Password, ServerProtocol.Imap4) { SSLConnection = true, }; if (GoogleRadioButton.IsChecked == true) { server.Server = "imap.gmail.com"; server.Port = 993; } else if (UkrRadioButton.IsChecked == true) { server.Server = "imap.ukr.net"; server.Port = 993; } MailClient client = new MailClient("TryIt"); // trial version try { client.Connect(server); var messages = client.GetMailInfos(); foreach (var m in messages) { Mail message = client.GetMail(m); mailMessages.Add(new MyMailMessage() { From = message.From.ToString(), Subject = message.Subject, AllText = message.TextBody, Text = new string(message.TextBody.Take(80).ToArray()).Replace("\n", "").Replace("\r", "") + "...", Date = message.ReceivedDate }); } isConnected = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private MailClient GetMailClient() { MailClient result; try { result = new MailClient("TryIt"); result.Connect(GetServer()); result.GetMailInfosParam.GetMailInfosOptions = GetMailInfosOptionType.NewOnly; } catch (Exception ex) { throw new Exception(ex.Message); } return(result); }
public IEnumerable <MailPreview> GetMailPreviews(DateTime startDate, string senders = null) { MailServer server = new MailServer(Imap4Server, eMailAddress, passWord, ServerProtocol.Imap4); MailClient client = new MailClient("TryIt"); server.SSLConnection = true; server.Port = 993; client.Connect(server); int count = client.GetMailCount(); string startDateString = startDate.ToString("dd-MMM-yyyy"); // MailInfo[] mailInfos = client.SearchMail("ALL SINCE 30-JUL-2019 OR FROM [email protected] FROM [email protected]");//client.GetMailInfos(); string searchFilter = "ALL SINCE " + startDateString + " OR FROM [email protected] FROM [email protected]"; if (!String.IsNullOrEmpty(senders)) { string[] senderArray = senders.Split(new char[] { ',', ';' }); if (senderArray.Length > 0) { searchFilter = "ALL OR"; foreach (string sender in senderArray) { searchFilter += " FROM " + sender.Trim(); } } } MailInfo[] mailInfos = client.SearchMail(searchFilter);//client.GetMailInfos(); List <MailPreview> mailPreviews = new List <MailPreview>(); for (int i = mailInfos.Length - 1; i >= 0; i--) { Mail mail = new Mail("TryIt"); mail.Load(client.GetMailHeader(mailInfos[i])); mailPreviews.Add(new MailPreview { Subject = mail.Subject, ReceivedDateTime = mail.ReceivedDate, From = String.Format("{0} <{1}>", mail.From.Name, mail.From.Address), MailInfo = mailInfos[i] }); } return(mailPreviews); }
public void ReadEmails() { try { //if(!oClient.Connected) oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; //Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", // info.Index, info.Size, info.UIDL); // Receive email from IMAP4 server Mail oMail = oClient.GetMail(info); var body = oMail.TextBody.Trim(); var subject = oMail.Subject.Trim().Replace("(Trial Version)", ""); //Console.WriteLine("From: {0}", oMail.From.ToString()); //Console.WriteLine("Subject: {0}\r\n", oMail.Subject); if (_handler != null && (string.IsNullOrEmpty(_acceptMsgFrom) || string.Compare(oMail.From.Address, _acceptMsgFrom, true) == 0)) { _handler(body); } // Generate an email file name based on date time. System.DateTime d = System.DateTime.Now; System.Globalization.CultureInfo cur = new System.Globalization.CultureInfo("en-US"); string sdate = d.ToString("ddMMyyyy-HHmmss", cur); string fileName = String.Format("{0}\\{1}_{2}.eml", _storePath, sdate, subject.Replace(':', '-')); // Save email to local disk oMail.SaveAs(fileName, true); oClient.ChangeMailFlags(info, "\\Seen"); oClient.Move(info, _readMails); } } catch (Exception ex) { Logger.LogException(ex); } }
static void Main(string[] args) { try { String email, pass; Console.WriteLine("Введите логин:"); email = Console.ReadLine(); Console.WriteLine("Введите пароль:"); pass = Console.ReadLine(); // mail.ru IMAP4 server is "imap.mail.ru" MailServer oServer = new MailServer("imap.mail.ru", email, pass, ServerProtocol.Imap4); MailClient oClient = new MailClient("TryIt"); // Set SSL connection oServer.SSLConnection = true; oServer.Port = 993; oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); Console.WriteLine("Подключение выполнено успешно. Всего писем: {0}\r\n", infos[infos.Length - 1].Index); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; Console.WriteLine("№: {0}; Размер: {1}; UIDL: {2}", info.Index, info.Size, info.UIDL); // Download email Mail oMail = oClient.GetMail(info); Console.WriteLine("От: {0}", oMail.From.ToString()); Console.WriteLine("Тема: {0}\r\n", oMail.Subject); } oClient.Quit(); Console.ReadLine(); } catch (Exception ep) { Console.WriteLine(ep.Message); Console.ReadLine(); } }
public void Init() { try { client.Connect(server); lConnect.Content = "Connected"; var messages = client.GetMailInfos(); foreach (var m in messages) { lbMail.Items.Add(m); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 下载指定的邮件数据信息到本地 /// </summary> /// <param name="dataInfo"></param> public void DownloadEmailInfo(EmailDataInfo dataInfo) { MailServer oServer = new MailServer(MailServerAddress, this.User, this.Password, true, ServerAuthType.AuthLogin, ServerProtocol.Imap4); oServer.Port = 993; MailClient oClient = new MailClient(LicenseCode); try { oClient.Connect(oServer); var mail = oClient.GetMail(dataInfo.MailInfo); this.BuildEmailDataInfo(dataInfo, mail, dataInfo.MailInfo); this.SaveMailDataInfo(dataInfo); dataInfo.IsDownloadedMail = true; } finally { oClient.Quit(); oClient.Close(); } }
public string ConnectMail() { try { // Gmail IMAP4 server is "imap.gmail.com" oServer = new MailServer("imap.gmail.com", idEmail, pwEmail, ServerProtocol.Imap4); oClient = new MailClient("TryIt"); // Set SSL connection, oServer.SSLConnection = true; // Set 993 IMAP4 port oServer.Port = 993; oClient.Connect(oServer); // Lookup folder based name. string folderName = "Steam Account Verification"; folder = SearchFolder(oClient.Imap4Folders, folderName); if (folder == null) { //Console.WriteLine(folder.Name); Console.WriteLine("Folder was not found"); return("FolderNotFound"); } // Select folder "Account Verification" oClient.SelectFolder(folder); return("Success"); } catch (Exception error) { string log = String.Format("{0:dd/MM/yyyy HH:mm:ss}", DateTime.Now) + ". Error: " + error.ToString() + "\r\n" + "\r\n"; WriteBugLogC(log); return(error.ToString()); } }
void AddUnreadMailsFromAccount(string emailName) { RegistryKey currentLoginKey = emailLoginsKey.OpenSubKey(emailName, true); LoginInfo loginInfo = new LoginInfo() { email = emailName, portSMTP = currentLoginKey.GetValue("portSMTP").ToString(), portIMAP = currentLoginKey.GetValue("portIMAP").ToString(), serverSMTP = currentLoginKey.GetValue("serverSMTP").ToString(), serverIMAP = currentLoginKey.GetValue("serverIMAP").ToString(), contracena = Program.DecryptStringFromBytes((byte[])currentLoginKey.GetValue("contracena", RegistryValueKind.Binary), Encoding.ASCII.GetBytes("1234567890123456"), Encoding.ASCII.GetBytes("1234567890123456")) }; MailServer mailServer = new MailServer(loginInfo.serverIMAP, loginInfo.email, loginInfo.contracena, ServerProtocol.Imap4) { SSLConnection = true, Port = Int32.Parse(loginInfo.portIMAP) }; MailClient mailClient = new MailClient("TryIt"); try { mailClient.Connect(mailServer); MailInfo[] infos = mailClient.GetMailInfos(); foreach (MailInfo mailInfo in infos) { if (!mailInfo.Read) { Mail mail = new Mail("TryIt"); mail.Load(mailClient.GetMailHeader(mailInfo)); unreadMails.Add(new UnreadMail() { emailLogin = emailName, idUIDL = mailInfo.UIDL, mailFrom = mail.From.Address, mailSubject = mail.Subject }); } } } catch (Exception ex) { unreadMails.Add(new UnreadMail() { emailLogin = "", idUIDL = "", mailFrom = emailName, mailSubject = "błąd połączeńa" }); } }
public User(string host, int port, string username, string password, bool useSSL) { Username = username; try { if (useSSL) { MailClient.ConnectSsl(host, port); MailClient.Login(username, password); } else { MailClient.Connect(host, port, username, password); } Good = true; } catch (Exception ex) { Logger.Log($"Failed to connect to mail server. User: [{username}], SSL: [{useSSL}]. Exception: {ex.Message}", LogType.WARNING); Good = false; } }
public List<PurchaseEmail> CheckEmail() { string curpath = Directory.GetCurrentDirectory(); string mailbox = String.Format("{0}\\inbox", curpath); string htmlMailbox = String.Format("{0}\\htmlInbox", curpath); // If the .eml and .htm folders do not exist, create it. if (!Directory.Exists(mailbox)) { Directory.CreateDirectory(mailbox); } if (!Directory.Exists(htmlMailbox)) { Directory.CreateDirectory(htmlMailbox); } // Gmail IMAP4 server is "imap.gmail.com" MailServer oServer = new MailServer("imap.gmail.com", "*****@*****.**", "**Jessica8", ServerProtocol.Imap4); MailClient oClient = new MailClient("TryIt"); // Set SSL connection, oServer.SSLConnection = true; // Set 993 IMAP4 port oServer.Port = 993; try { oClient.Connect(oServer); MailInfo[] infos = oClient.GetMailInfos(); for (int i = 0; i < infos.Length; i++) { MailInfo info = infos[i]; //Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", info.Index, info.Size, info.UIDL); // Download email from GMail IMAP4 server Mail oMail = oClient.GetMail(info); if (oMail.From.ToString().Contains("*****@*****.**")) { // Generate an email file name based on date time. System.DateTime d = System.DateTime.Now; var cur = new System.Globalization.CultureInfo("en-US"); string sdate = d.ToString("yyyyMMddHHmmss", cur); string fileName = String.Format("{0}\\{1}{2}{3}.eml", mailbox, sdate, d.Millisecond.ToString("d3"), i); // Save email to local disk oMail.SaveAs(fileName, true); } // Mark email as deleted in GMail account. oClient.Delete(info); } // Quit and purge emails marked as deleted from Gmail IMAP4 server. oClient.Quit(); } catch (Exception ep) { MessageBox.Show(ep.Message); } // Get all *.eml files in specified folder and parse it one by one. string[] files = Directory.GetFiles(mailbox, "*.eml"); var purchaseList = new List<PurchaseEmail>(); for (int i = 0; i < files.Length; i++) { var convertedMessage = ConvertMailToHtml(files[i]); if (System.IO.File.Exists(files[i])) { // Use a try block to catch IOExceptions, to // handle the case of the file already being // opened by another process. try { System.IO.File.Delete(files[i]); } catch (System.IO.IOException e) { MessageBox.Show(e.Message); } } purchaseList.Add(convertedMessage); } return purchaseList; }