private Pop3 CreateMailClient() { var client = new Pop3(); if (Pars.UseSsl) { client.SSLConfiguration.EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12; if (Pars.Port == 0) { client.ConnectSSL(Pars.IncomingServer); } else { client.ConnectSSL(Pars.IncomingServer, Pars.Port); } } else { if (Pars.Port == 0) { client.Connect(Pars.IncomingServer); } else { client.Connect(Pars.IncomingServer, Pars.Port); } } client.Login(Pars.Username, Pars.Password); client.ServerCertificateValidate += OnCertificateValidate; return(client); }
public void Connect(string server, string port, string encryption) { int portInt; if (int.TryParse(port, out portInt)) { if ((string)encryption == "STARTTLS") { pop.Connect(server, portInt); pop.StartTLS(); } else { pop.ConnectSSL(server, portInt); } } else { if ((string)encryption == "STARTTLS") { pop.Connect(server); pop.StartTLS(); } else { pop.ConnectSSL(server); } } }
// Connect to POP3 public async Task <Pop3> ConnectPop3(Model.UserInfo userInfo) { var serverconnTask = Task.Run(() => { Pop3 pop3 = new Pop3(); if (userInfo.EncryptionType == Model.Enum.EncryptionType.Unencrypted) { pop3.Connect(userInfo.Server, userInfo.Port); } else if (userInfo.EncryptionType == Model.Enum.EncryptionType.SSLTLS) { pop3.ConnectSSL(userInfo.Server, userInfo.Port); } else { pop3.Connect(userInfo.Server, userInfo.Port); pop3.StartTLS(); } pop3.UseBestLogin(userInfo.UserName, userInfo.Password); return(pop3); }); var completedTask = await Task.WhenAny(serverconnTask); if (completedTask == serverconnTask) { return(await serverconnTask); } else { throw new TimeoutException("server Connection timed out"); } }
/// <summary> /// Connects to POP3 server. /// </summary> /// <param name="host">Host name or IP address.</param> /// <param name="serverEncryption">Server encryption (SslTls, Unencrypted, StartTls)</param> /// <seealso cref="M:Limilabs.Client.ClientBase.Connect(System.String,System.Int32,System.Boolean)" /> /// <exception cref="T:Limilabs.Client.ServerException">DNS resolving error, connection error.</exception> /// <exception cref="T:Limilabs.Client.POP3.Pop3ResponseException">Initial error response.</exception> public void Connect(MailServerEncryption serverEncryption, string host) { switch (serverEncryption) { case MailServerEncryption.SslTls: { _pop3.ConnectSSL(host); break; } case MailServerEncryption.Unencrypted: { _pop3.Connect(host); break; } case MailServerEncryption.StartTls: { _pop3.Connect(host); _pop3.StartTLS(); break; } default: { _pop3.Connect(host); break; } } }
private IList <MailModel> GetMessagesPop3(ServerInfoModel serverInfoModel) { using (var pop3 = new Pop3()) { pop3.ConnectSSL(serverInfoModel.Server, serverInfoModel.Port); pop3.Login(serverInfoModel.User, serverInfoModel.Password); return(GetMessagesPop3(pop3).ToList()); } }
private void ConnectAndLogin(Pop3 imap) { if (Encryption == Constants.Encryptions.SSL_TLS) { imap.ConnectSSL(Host, PortNumber); } else if (Encryption == Constants.Encryptions.START_TLS) { imap.Connect(Host, PortNumber); imap.StartTLS(); } else { imap.Connect(Host, PortNumber); } imap.UseBestLogin(Username, Password); }
static void Main(string[] args) { using (Pop3 pop3 = new Pop3()) { pop3.ConnectSSL("pop.gmail.com"); // or ConnectSSL for SSL pop3.UseBestLogin(Email, PW); List <string> uids = pop3.GetAll(); foreach (string uid in uids) { IMail email = new MailBuilder() .CreateFromEml(pop3.GetMessageByUID(uid)); Console.WriteLine(email.Subject); } Console.ReadKey(); pop3.Close(); } }
public MainWindow() { InitializeComponent(); Mails = new List <MailDisplay>(); string path = "localMails"; if (File.Exists(path)) { Mails.AddRange(JsonConvert.DeserializeObject <List <MailDisplay> >(File.ReadAllText(path))); } using (Pop3 pop3 = new Pop3()) { pop3.ConnectSSL("pop.mail.ru", 995); // or ConnectSSL for SSL pop3.UseBestLogin("*****@*****.**", "123456Aa"); foreach (string uid in pop3.GetAll()) { if (Mails.Any(m => m.Id == uid)) { continue; } byte[] eml = pop3.GetMessageByUID(uid); IMail mail = new MailBuilder().CreateFromEml(eml); MailDisplay mailDisplay = new MailDisplay { Id = uid, Sender = mail.Sender.Name, Subject = mail.Subject, Text = mail.Text, TimeSent = mail.Date }; Mails.Add(mailDisplay); } } File.WriteAllText(path, JsonConvert.SerializeObject(Mails)); mailList.ItemsSource = Mails; }
public Pop3Client(string username, string password, string server, int port, EncryptionType encryptionType) : base(username, encryptionType) { _pop3 = new Pop3(); if (encryptionType == EncryptionType.SSLTLS) { _pop3.ConnectSSL(server, port); } else { _pop3.Connect(server, port); if (encryptionType == EncryptionType.StartTLS) { _pop3.StartTLS(); } } _pop3.Login(username, password); }
private async Task <Pop3> Connect(UserInfo userInfo) { var timeout = _settings.ConnectionTimeOutMilliseconds; Task timeoutTask = Task.Delay(timeout); var connectionTask = Task.Run(() => { Pop3 pop3 = _pop3Factory.GetInstance(); if (userInfo.EncryptionType == Model.Enum.EncryptionType.Unencrypted) { pop3.Connect(userInfo.Server, userInfo.Port); } else if (userInfo.EncryptionType == Model.Enum.EncryptionType.SslTls) { pop3.ConnectSSL(userInfo.Server, userInfo.Port); } else { pop3.Connect(userInfo.Server, userInfo.Port); pop3.StartTLS(); } pop3.UseBestLogin(userInfo.UserName, userInfo.Password); return(pop3); }); var completedTask = await Task.WhenAny(connectionTask, timeoutTask); if (completedTask == connectionTask) { return(await connectionTask); } else { throw new TimeoutException("Connection with the server timed out"); } }
void loginmail() { try { clientmail = new SmtpClient("smtp.gmail.com", 587); pop3 = new Pop3(); pop3.ConnectSSL("pop.gmail.com", 995); clientmail.EnableSsl = true; clientmail.Credentials = new NetworkCredential(textBox_gmailSend.Text, textBox_password.Text); pop3.Login(textBox_gmailSend.Text, textBox_password.Text); MessageBox.Show(" Tài khoản đăng nhập thành công", "Đăng nhập hệ thống", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Đăng nhập thất bại", "Đăng nhập hệ thống", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.ToString()); } }
public void BaixarPop3() { using (Pop3 pop3 = new Pop3()) { //pop3.Connect("host sem SSL"); pop3.ConnectSSL(this.hostPop3); pop3.UseBestLogin(this.MeuEmaail, this.MinhaSenha); foreach (string uid in pop3.GetAll()) { IMail email = new MailBuilder() .CreateFromEml(pop3.GetMessageByUID(uid)); Console.WriteLine(email.Subject); // salva anexo no disco foreach (MimeData mime in email.Attachments) { mime.Save(string.Concat(this.PathAnexo, mime.SafeFileName)); } } pop3.Close(); } }
/// <summary> /// Opens connection with email server based on UserAccount user settings /// </summary> /// <param name="ua"></param> /// <returns></returns> protected int ConnectToServer(UserAccount ua) { _ua = ua; try { if (ua.InUserProtocol == "POP3") { // Connect to Server if (ua.InUserSSL == "SSL") { _pop3.ConnectSSL(ua.InUserServer, Int32.Parse(ua.InUserPort)); } else { _pop3.Connect(ua.InUserServer, Int32.Parse(ua.InUserPort)); } // Use credentials _pop3.UseBestLogin(ua.UserUsername, ua.UserPassword); ua.SettingsVerified = true; return(1); } else { _imap.ConnectSSL(ua.InUserServer); _imap.Login(ua.UserUsername, ua.UserPassword); ua.SettingsVerified = true; return(1); } } catch (Exception ex) { ua.SettingsVerified = false; return(0); } }
protected override void Poll() { bool emailDownloaded = false; Exception error = null; try { PollBegin(); using (Pop3 pop3 = new Pop3()) { switch (_sslType) { case SSLType.None: pop3.Connect(_host, _port); break; case SSLType.SSL: pop3.ConnectSSL(_host, _port); break; case SSLType.TLS: pop3.Connect(_host, _port); pop3.STLS(); break; } pop3.UseBestLogin(_username, _password); List <string> serverUids = pop3.GetAll(); MessageStoreCollection localMessageStore = MessageStoreManager.LoadLocalMessageStore(_username, _host); if (localMessageStore != null) { MessageStoreManager.RemoveMessagesNoLongerOnServer(ref localMessageStore, serverUids); List <string> uidsToCheck = MessageStoreManager.GetMessagesToCheck(localMessageStore, serverUids); foreach (string uid in uidsToCheck) { //string fileName; byte[] eml = pop3.GetMessageByUID(uid); IMail email = new MailBuilder().CreateFromEml(eml); //SpoolEmlViaDisk(pop3.GetMessageByUID(uid), out fileName); MessageStoreMessage theMessage = new MessageStoreMessage(uid); if (ProcessEmailAttachments(email) > 0) { emailDownloaded = true; //Only populate the extra data for game emails if (email.From.Count > 0) { theMessage.From = email.From[0].Address; } theMessage.Subject = email.Subject; if (email.Date.HasValue) { theMessage.Date = email.Date.Value.ToString(); theMessage.DateTicks = email.Date.Value.Ticks.ToString(); } //In case the email doesn't come down with a good date if (string.IsNullOrEmpty(theMessage.Date)) { DateTime stamp = DateTime.Now; theMessage.Date = stamp.ToString(); theMessage.DateTicks = stamp.Ticks.ToString(); } theMessage.FileName = GetAttachmentsString(email); } localMessageStore.Messages.Add(theMessage); //ClearSpooledEml(fileName); } } else { //New message store, add all currently on server localMessageStore = new MessageStoreCollection(serverUids); } MessageStoreManager.SaveLocalMessageStore(_username, _host, localMessageStore); localMessageStore.Dispose(); localMessageStore = null; pop3.Close(); } } catch (Exception ex) { error = ex; Trace.TraceError(ex.ToString()); Trace.Flush(); } finally { PollEnd(emailDownloaded, error); } }
static public string getmsgemail(string Steamlogin) { using (Pop3 pop3 = new Pop3()) { if (Config.emailssl == true) { try { pop3.ConnectSSL(Config.emailserver); } catch (Exception e) { errorlog(e.Message); return(null); } } else { try { pop3.Connect(Config.emailserver); } catch (Exception e) { errorlog(e.Message); return(null); } } try { pop3.UseBestLogin(Config.emaillogin, Config.emailpassword); } catch (Exception e) { errorlog(e.Message); return(null); } MailBuilder builder = new MailBuilder(); foreach (string uid in pop3.GetAll()) { IMail email = builder.CreateFromEml( pop3.GetMessageByUID(uid)); long unixTime = (long)(email.Date.Value - new DateTime(1970, 1, 1)).TotalSeconds; long epochTicks = new DateTime(1970, 1, 1).Ticks; long unixfTime = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond) + 10800; long unixffTime = unixfTime - unixTime; if (unixffTime <= 300) { string text1 = getBetween(email.Text, Steamlogin.ToLower() + ":", "This email was generated because"); if (text1 != null) { return(text1.Replace("\r\n", string.Empty) .Replace("\n", string.Empty) .Replace("\r", string.Empty)); } } } errorlog("Не могу найти письмо!"); return(null); } }
static void Main(string[] args) { Console.WriteLine("Veuillez entrer les éléments de facturation du client :"); string input = Console.ReadLine(); HuffmanTree huffmanTree = new HuffmanTree(); // Construire l'arbre de huffman huffmanTree.Build(input); // Encoder BitArray encoded = huffmanTree.Encode(input); //on retourne le nombre d'octets du message lu au clavier Console.WriteLine(); Console.WriteLine("Votre texte est de " + input.Length + " octets"); //on ouvre une session de connexion sur gmail à travers smtp try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); //expéditeur mail.To.Add("*****@*****.**"); //recepteur mail.Subject = "Informations client"; //objet //ic on affiche d'abord le message compréssé chez l'expéditeur Console.WriteLine(); int cpt = 0; //j'initialise un compte ici pour avoir le nombre de bit à la fin de la compression Console.Write("Compressé: "); foreach (bool bit in encoded) { Console.Write((bit ? 1 : 0) + ""); cpt = cpt + 1; } Console.WriteLine(); Console.WriteLine("le texte compréssé est de " + (cpt / 8 + 1) + " octets"); Console.WriteLine(); Console.WriteLine("En cours d'envoi à " + mail.To + "..."); /*foreach (bool bit in encoded) * { * mail.Body = (bit ? 1 : 0) + ""; * } * Console.WriteLine();*/ string chaine; string message = ""; foreach (bool bit in encoded) { chaine = (bit ? 1 : 0) + ""; message = $"{message}{chaine}"; } mail.Body = message; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "testisj2019"); SmtpServer.EnableSsl = true; Console.WriteLine(); SmtpServer.Send(mail); Console.WriteLine("Votre mail à été envoyé avec succes!!!");//Message succes } catch (Exception ex) { Console.WriteLine(ex.ToString()); } //cette partie du code permet de lire les mails de l'adresse passée en paramètre try { using (Pop3 pop3 = new Pop3()) { pop3.ConnectSSL("pop.gmail.com"); // or ConnectSSL for SSL pop3.Login("*****@*****.**", "mayelle2010"); List <string> uids = pop3.GetAll(); foreach (string uid in uids) { IMail email = new MailBuilder() .CreateFromEml(pop3.GetMessageByUID(uid)); Console.WriteLine(""); Console.WriteLine(email.Date); Console.WriteLine(email.From); Console.WriteLine(email.Subject); } pop3.Close(); } } catch (Limilabs.Client.ServerException e) { Console.WriteLine(e.ToString()); } }
private void ReadMailBox(Configuration config) { log.Info("Check for Mail"); if (!string.IsNullOrEmpty(config.AppSettings.Settings["POPServer"].Value)) { try { if (config.AppSettings.Settings["MailType"].Value == "POP") { using (Pop3 pop3 = new Pop3()) { pop3.ServerCertificateValidate += new ServerCertificateValidateEventHandler(Validate); pop3.ConnectSSL(config.AppSettings.Settings["POPServer"].Value); //pop3.STLS(); pop3.Login(config.AppSettings.Settings["POPMailUser"].Value, config.AppSettings.Settings["POPMailPassword"].Value); foreach (string uid in pop3.GetAll()) { string eml = pop3.GetMessageByUID(uid); IMail mail = new MailBuilder() .CreateFromEml(eml); try { mail.Attachments.ForEach(att => { processAttachment(att, config, mail.Sender.Address); }); pop3.DeleteMessageByUID(uid); } catch (IOException ex) { log.Error(ex.InnerException); } catch (Exception ex) { log.Error(ex); } } pop3.Close(); } } else { #region IMAP Imap imap = new Imap(); //imap.User = ; //imap.Password =; imap.Connect(config.AppSettings.Settings["POPServer"].Value); imap.Login(config.AppSettings.Settings["POPMailUser"].Value, config.AppSettings.Settings["POPMailPassword"].Value); imap.SelectInbox(); List <long> uidList = imap.SearchFlag(Flag.Unseen); log.Debug("Go to process: " + uidList.Count + "mails"); foreach (long uid in uidList) { ISimpleMailMessage imail = new SimpleMailMessageBuilder() .CreateFromEml(imap.GetMessageByUID(uid)); log.Info("Email received: " + imail.From.First().Name); foreach (var att in imail.Attachments) { try { processAttachment(att, config, imail.From.First().Address); } catch (IOException ex) { log.Error(ex.InnerException); imap.FlagMessageByUID(uid, Flag.Flagged); imap.MarkMessageSeenByUID(uid); } catch (Exception ex) { log.Error(ex); imap.FlagMessageByUID(uid, Flag.Flagged); imap.MarkMessageSeenByUID(uid); } } imap.MarkMessageSeenByUID(uid); imap.DeleteMessageByUID(uid); } imap.Close(true); #endregion } log.Info("Mail check complete"); } catch (Exception ex) { log.Error(ex.InnerException); } } else { log.Info("Mail check skipped!"); } }