Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Encrypting password for email
#31
Macro C# receive email - OpenPop
Code:
Copy      Help
;This macro uses OpenPop.NET library. Download it from https://sourceforge.net/projects/hpop/ and extract OpenPop.dll to QM folder.

out

;get password from registry HKEY_CURRENT_USER\SOFTWARE\GinDi\QM2\User\p
str password; if(!rget(password "gmail" "\p")) end "failed"

;download messages from gmail account Inbox folder
ARRAY(str) a=CsFunc("" "pop.gmail.com" 995 1 "user name" password)

;parse and display messages
out a.len
int i
for i 0 a.len
,MailBee.Message m._create
,m.RawBody=a[i]
,str from(m.FromAddr) subject(m.Subject) body
,body=iif(m.BodyFormat=1 m.GetPlainFromHtml(m.BodyText) m.BodyText)
,out F"<><Z 0x80E080>{from}    {subject}</Z>[]{body}"
,


#ret
//C# code
using System;
using System.Collections.Generic;
using OpenPop;
using OpenPop.Pop3;
using OpenPop.Mime;

public class Email
{
,public static string[] Receive(string server, int port, bool useSsl, string user, string password)
,{
,,var a=new List<string>();
,,foreach(var m in FetchAllMessages(server, port, useSsl, user, password)) {
,,,//Out(m.Headers.From);
,,,a.Add(System.Text.Encoding.UTF8.GetString(m.RawMessage));
,,}
,,return a.ToArray();
,}
,
,static void Out(object s) { Console.WriteLine(s); }
,
/// <summary>
/// Example showing:
///  - how to fetch all messages from a POP3 server
/// </summary>
/// <param name="hostname">Hostname of the server. For example: pop3.live.com</param>
/// <param name="port">Host port to connect to. Normally: 110 for plain POP3, 995 for SSL POP3</param>
/// <param name="useSsl">Whether or not to use SSL to connect to server</param>
/// <param name="username">Username of the user on the server</param>
/// <param name="password">Password of the user on the server</param>
/// <returns>All Messages on the POP3 server</returns>
public static List<Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password)
{
;;;;// 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);

;;;;;;;;// Get the number of messages in the inbox
;;;;;;;;int messageCount = client.GetMessageCount();

;;;;;;;;// We want to download all messages
;;;;;;;;List<Message> allMessages = new List<Message>(messageCount);

;;;;;;;;// Messages are numbered in the interval: [1, messageCount]
;;;;;;;;// Ergo: message numbers are 1-based.
;;;;;;;;// Most servers give the latest message the highest number
;;;;;;;;for (int i = messageCount; i > 0; i--)
;;;;;;;;{
;;;;;;;;;;;;allMessages.Add(client.GetMessage(i));
;;;;;;;;}

;;;;;;;;// Now return the fetched messages
;;;;;;;;return allMessages;
;;;;}
}


}
#32
I try OpenPop method with gmail account and appears this error:
Server did not accept user credentials
en OpenPop.Pop3.Pop3Client.Authenticate(String username, String password, AuthenticationMethod authenticationMethod)
en Email.FetchAllMessages(String hostname, Int32 port, Boolean useSsl, String username, String password)
en Email.Receive(String server, Int32 port, Boolean useSsl, String user, String password).

Sorry, I'm not able to do :-(
Maybe just the IMAP option for Gmail accounts / Yahoo. I try...
I will prove if POP3 method works with a own domain email account ...
#33
POP must be enabled in gmail settings. Maybe IMAP too, if not enabled by default. Now I don't remember, probably POP was disabled by default.


Forum Jump:


Users browsing this thread: 1 Guest(s)