Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using OpenPop.Mime;
- using OpenPop.Mime.Header;
- using OpenPop.Pop3;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace bs_torrent_client
- {
- class Program
- {
- static void Main(string[] args)
- {
- string username = "xxxxxxxxx";
- string password = "xxxxxxxxx";
- string hostname = "pop.gmail.com";
- HeadersFromAndSubject(hostname, 995, true, username, password, 5);
- }
- public static void HeadersFromAndSubject(string hostname, int port, bool useSsl, string username, string password, int messageNumber)
- {
- // The client disconnects from the server when being disposed
- using (Pop3Client client = new Pop3Client())
- {
- // Connect to the server
- client.Connect(hostname, port, useSsl);
- // Authenticate ourselves towards the server
- client.Authenticate(username, password, OpenPop.Pop3.AuthenticationMethod.UsernameAndPassword);
- // We want to check the headers of the message before we download
- // the full message
- MessageHeader headers = client.GetMessageHeaders(messageNumber);
- RfcMailAddress from = headers.From;
- string subject = headers.Subject;
- if (from.HasValidMailAddress && from.Address.Equals("XXXXXXXXX"))
- {
- // Download the full message
- Message message = client.GetMessage(messageNumber);
- // We know the message contains an attachment with the name "useful.pdf".
- // We want to save this to a file with the same name
- foreach (MessagePart attachment in message.FindAllAttachments())
- {
- if (attachment.FileName.Equals("XXXXXXXX"))
- {
- // Save the raw bytes to a file
- File.WriteAllBytes(attachment.FileName, attachment.Body);
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement