Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Encrypting password for email
#1
How do I make this work. What is the email password encrypted as? How can I do that in my code.

Please fix it up so it works Smile

Thanks,
Jimmy Vig


Function Gmail_DownLoad
Code:
Copy      Help
function str'EMAIL_ACCOUNT str'ENCRYPTED_PASSWORD [str'DownLoadFolder]

;EXAMPLE:

;Gmail_DownLoad "User@gmail.com" "Password" "$desktop$/Emails"

ENCRYPTED_PASSWORD.encrypt(8)
str EMAIL=
;smtp_server smtp.gmail.com
;smtp_port 465
;smtp_user EMAIL_ACCOUNT
;smtp_password ENCRYPTED_PASSWORD
;smtp_auth 2
;smtp_secure 1
;smtp_timeout 60
;smtp_email EMAIL_ACCOUNT
;smtp_displayname EMAIL_ACCOUNT
;smtp_replyto EMAIL_ACCOUNT
;pop_server pop.gmail.com
;pop_port 995
;pop_user EMAIL_ACCOUNT
;pop_password ENCRYPTED_PASSWORD
;pop_auth 0
;pop_secure 1
;pop_timeout 60

EMAIL.findreplace("EMAIL_ACCOUNT" EMAIL_ACCOUNT)
EMAIL.findreplace("ENCRYPTED_PASSWORD" ENCRYPTED_PASSWORD)
ARRAY(str) a
ReceiveMail(EMAIL 0x100 DownLoadFolder a)
#2
Email passwords cannot be encrypted in code. Only email account dialog knows how to encrypt it.
#3
That's a bummer man. I was really hoping to get this code up and running.

There's no way to emulate the encryption that the Email Dialog performs?
#4
No. Tomorrow I'll write function that supports nonencrypted password.
#5
Thank you.
#6
1. If System folder is read-only: right click System folder, click Folder Properties, uncheck read-only, OK.
2. Find and delete member function EMAILACCOUNT.Get.
3. Optionally make System folder read-only.
4. Import the attached file. It contains modified EMAILACCOUNT.Get. Place it anywhere.

To use non encrypted password with email functions, prepend ! to the password.

In the future, after upgrading QM, delete the imported function.

Function Gmail_DownLoad
Code:
Copy      Help
function str'EMAIL_ACCOUNT str'PASSWORD [str'DownLoadFolder]

;EXAMPLE:

;Gmail_DownLoad "User@gmail.com" "Password" "$desktop$/Emails"

str EMAIL=
;pop_server pop.gmail.com
;pop_port 995
;pop_user EMAIL_ACCOUNT
;pop_password !PASSWORD
;pop_auth 0
;pop_secure 1
;pop_timeout 60

EMAIL.findreplace("EMAIL_ACCOUNT" EMAIL_ACCOUNT)
EMAIL.findreplace("PASSWORD" PASSWORD)
ARRAY(str) a
ReceiveMail(EMAIL 0x100 DownLoadFolder a)


Attached Files
.qml   EMAILACCOUNT.Get.qml (Size: 2.82 KB / Downloads: 597)
#7
Works great. Just what I wanted.

Thanks Gint Smile
#8
Can this be done with sending mail too?

Thanks!
Jim
#9
Oh...adding ! to beginning of the password works.

-Jim
#10
I followed the instructions, and I can not erase the ___EMAILACCOUNT.Get function.
Can I create a small application to encrypt passwords? I can not find help in this regard.
I would like too to make a little program for my users can generate their encrypted passwords and store them in the configuration INI file of my application. Thanks.
#11
Now don't need to replace ___EMAILACCOUNT.

Macro Encrypted password generator
Code:
Copy      Help
;Change myEncryptionKey.
;Also you can encrypt this macro.

;g1
str password
if(!inp(password "Encrypted password will be stored in the clipboard." "Password" "*")) ret
if(password.len<6) mes "min 6 characters" "" "i"; goto g1
str encryptedPassword.encrypt(1|4 password "myEncryptionKey")
encryptedPassword.setclip

Macro Test encrypted password
Code:
Copy      Help
;Change myEncryptionKey to match that in "Encrypted password generator".
;Also you can encrypt this macro.

str encryptedPassword="kkdodhfifpfpdkshgkd" ;;paste the result of macro "Encrypted password generator"

str password.decrypt(1|4 encryptedPassword "myEncryptionKey")
_s=
F
;...
;smtp_password !{password}
;...
SendMail "email" "subject" "text" 0 "" "" "" "" "" _s
#12
Thank You very much !!

But the main problem continues. If I put an encrypted password, Sendmail and RetrieveMessages work properly.

If I put a password unencrypted to call those commands, I get the following error:

Email Server Error: some email account settings missing in Line: 11519 Iid: 5 Place: 11519 Code: 0 Source: 3 Command: foreach m p.RetrieveMessages(Flags1 0 EmailServer)...

This error occurs to me in the same way with POP server (with Retrievemessages command) as the SMTP server (with sendmail command). Actual server configuration (It works well with Encripted Password generated by Quickmacros Assistant):

str EmailServer=
;smtp_server smtp.mail.yahoo.com
;smtp_port 465
;smtp_user x@yahoo.es (real email is hidden)
;smtp_password PassWithoutEncrypt (or ;smtp_password !PassWithoutEncrypt)
;smtp_auth 1
;smtp_secure 1
;smtp_timeout 60
;smtp_email x@yahoo.es
;smtp_displayname x@yahoo.es
;smtp_replyto x@yahoo.es
;pop_server pop.mail.yahoo.com
;pop_port 995
;pop_user x@yahoo.es
;pop_password PassWithoutEncrypt (or ;pop_password !PassWithoutEncrypt)
;pop_auth 0
;pop_secure 1
;pop_timeout 60

If I try to insert the admiration (!) As in the attached example before the password, I get error: "Incorrect username or password".
#13
Macro Macro2764
Code:
Copy      Help
str PassWithoutEncrypt="PassWithoutEncrypt"


;add this line to see is the password correct
out F"'{PassWithoutEncrypt}'"

str EmailServer=
F
;smtp_server smtp.mail.yahoo.com
;smtp_port 465
;smtp_user x@yahoo.es (real email is hidden)
;smtp_password !{PassWithoutEncrypt}
;smtp_auth 1
;smtp_secure 1
;smtp_timeout 60
;smtp_email x@yahoo.es
;smtp_displayname x@yahoo.es
;smtp_replyto x@yahoo.es
;pop_server pop.mail.yahoo.com
;pop_port 995
;pop_user x@yahoo.es
;pop_password !{PassWithoutEncrypt}
;pop_auth 0
;pop_secure 1
;pop_timeout 60
SendMail "email" "subject" "text" 0 "" "" "" "" "" EmailServer
#14
I read the configuration parameters from an .ini file. I do a reading, and I concatenating the parameters.
¿Why I do not get the same result? I attach the source code.
Continuous testing with unencrypted password. The values of the other parameters are the same as those listed above. This code does not work me. Appears error: Incorrect username or password:

ARRAY(str) var_name.create(17)
ARRAY(str) var_result.create(17)

var_name[0]="smtp_server"
var_name[1]="smtp_port"
var_name[2]="smtp_user"
var_name[3]="smtp_password"
var_name[4]="smtp_auth"
var_name[5]="smtp_secure"
var_name[6]="smtp_timeout"
var_name[7]="smtp_email"
var_name[8]="smtp_displayname"
var_name[9]="smtp_replyto"
var_name[10]="pop_server"
var_name[11]="pop_port"
var_name[12]="pop_user"
var_name[13]="pop_password"
var_name[14]="pop_auth"
var_name[15]="pop_secure"
var_name[16]="pop_timeout"

str EmailServer=""

for i 0 17
if(rget(var_result[i] var_name[i] "EMAIL SERVER" INIFilename))
err ...
else
if var_result[i]
TextLog=F"INI File Error. The value or the Key: {var_name[i]}, Section: [EMAIL SERVER] File: {INIFilename} does not exist"
out TextLog
mes TextLog NameApp
end

EmailServer=
F
;smtp_server {var_result[0]}
;smtp_port {var_result[1]}
;smtp_user {var_result[2]}
;smtp_password !{var_result[3]}
;smtp_auth {var_result[4]}
;smtp_secure {var_result[5]}
;smtp_timeout {var_result[6]}
;smtp_email {var_result[7]}
;smtp_displayname {var_result[8]}
;smtp_replyto {var_result[9]}
;pop_server {var_result[10]}
;pop_port {var_result[11]}
;pop_user {var_result[12]}
;pop_password !{var_result[13]}
;pop_auth {var_result[14]}
;pop_secure {var_result[15]}
;pop_timeout {var_result[16]}
...
SendMail F"{FromEmail}" F"Rv: {EmailSubject}" F"{EmailBody2}" TestEmail FileAttach CCEmail BCCEmail F"X-Mailer: {NameApp}" "" EmailServer

Thanks.
#15
If you insert

out EmailServer

before SendMail, and see all correct values, then I have no ideas why it does not work. Unless using a very old Quick Macros version that still did not support !password.
#16
Try this:
Log in to your yahoo email account, go to
Help (Setting) -> Account Info -> Account Security -> Allow apps that use less secure sign in
and turn it on.
and log out
and re-test it.
#17
The configuration to read emails from Yahoo less safely was already enabled, thank you.
Initially I installed version 2.4.3.8 Quickmacros. Then, seeing that it was not compatible with Windows 2000, installed version 2.4.2.2 above. I realized that I did not properly compiled to run the application that was developing, and I returned to install version 2.4.3.8 above.

Now I uninstalled completely with the uninstaller, delete the folder QuickMacros 2 "Program Files (x86)" directory, and I re-install it.

After checking with "out EmailServer", that admiration (!) Appears in front of the password, and I try again, continues to fail, both as executable directly from the shell.

How I could confirm whether I am using the correct version of the file? Can it affect the content of directory user documents\My QM? This directory is not removed it.

Thanks again.
#18
The application works correctly without admiration (!) and with password encripted from "QM Email Settings" Window.
I also solves the problem if know the passphrase encription used in that window (in "To String" button)... or to change this passphrase from within the application as a parameter...
#19
As an alternative, can use C# to send email.

from http://stackoverflow.com/a/32336/2547338

Macro C# send email
Code:
Copy      Help
CsFunc("" "password" "to@example.com" "Subject" "Body")


#ret
//C# code
using System;
using System.Net;
using System.Net.Mail;

public class Email
{
static public void Send(string password, string email, string subject, string body)
{
var fromAddress = new MailAddress("xxx@gmail.com", "From Name");
var toAddress = new MailAddress(email);

var smtp = new SmtpClient
{
;;;;Host = "smtp.gmail.com",
;;;;Port = 587,
;;;;EnableSsl = true,
;;;;DeliveryMethod = SmtpDeliveryMethod.Network,
;;;;UseDefaultCredentials = false,
;;;;Credentials = new NetworkCredential(fromAddress.Address, password)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
;;;;Subject = subject,
;;;;Body = body
})
{
;;;;smtp.Send(message);
}
}
}

But this will not work on Windows 2000. Also on XP without .NET.
#20
And to receive mails what alternative is there?
#21
Does this C# email function work?
#22
AFAIK .NET does not have a POP3 or IMAP class, and there are no Windows API for it. Need to find an IMAP or POP3 library somewhere.
#23
To try Sendmail C# code:

CsFunc("" "PasswithoutEncrypt" "destinationemail@hotmail.com" "Test Sendmail C# 05-09-2016" "Body Text")


#ret
//C# code
using System;
using System.Net;
using System.Net.Mail;

public class Email
{
static public void Send(string password, string email, string subject, string body)
{
var fromAddress = new MailAddress("emailaccount@yahoo.es", "Email Account Name");
var toAddress = new MailAddress(email);

var smtp = new SmtpClient
{
Host = "smtp.mail.yahoo.com",
Port = 465,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, password)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
}
}

---------
ERROR:

Error (RT) in <open ":3047: /0">Sendmail C code: 0x80131500,
Error al enviar correo.
en System.Net.Mail.SmtpClient.Send(MailMessage message)
en Email.Send(String password, String email, String subject, String body).
#24
I tested with gmail, cannot test with yahoo.
Try to find C# example for yahoo.
#25
I am delighted with Quickmacros because I had removed complexity for development. I find it incomprehensible that there are no libraries for reading emails in many tools. In fact, when I bought Quickmacros went looking for this functionality. I'm a frustrated developer, because I can not find tools powerful, easy to use development, and a good debugger. I'll have to leave Quickmacros, at least for this project. I am an excellent analyst, but a bad programmer source code :-(

I appreciate your interest, but I will not keep trying this way. I can send emails with many utilities, but I can not read with any who knows. Please, let's leave it, and thank you very much.
#26
This is a working sample, just substitute all necessary items before using it.

Macro C# Send Email with Yahoo Mail
Code:
Copy      Help
;To get encryptedPassword, just run Gintaras' "Encrypted password generator" macro to generate it
str encryptedPassword="MpLtzu1l0Q1gze3/t3lvmOBEjEkGNibTBQ=="
str password.decrypt(1|4 encryptedPassword "myEncryptionKey")
;out F"password = {password}"
str emailTo="recipient email"
str subject="Subject"
str body="Body"
CsFunc("" password emailTo subject body)

#ret
//C# code
using System;
using System.Net;
using System.Net.Mail;

public class Email
{
,static public void Send(string password, string emailTo, string subject, string body)
,{
,,string smtpAddress = "smtp.mail.yahoo.com";
,,int portNumber = 587;
,,bool enableSSL = true;
,,string emailFrom = "YourEmail@yahoo.com";
,,using (MailMessage mail = new MailMessage())
,,{
,,,mail.From = new MailAddress(emailFrom);
,,,mail.To.Add(emailTo);
,,,mail.Subject = subject;
,,,mail.Body = body;
,,,mail.IsBodyHtml = true;  // Can set to false, if you are sending pure text.
,,
,,,mail.Attachments.Add(new Attachment(@"C:\Temp\File1.txt"));
,,,mail.Attachments.Add(new Attachment(@"C:\Temp\File2.txt"));
,,
,,,using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
,,,{
,,,,smtp.Credentials = new NetworkCredential(emailFrom, password);
,,,,smtp.EnableSsl = enableSSL;
,,,,smtp.Send(mail);
,,,}
,,}
,}
}
#27
If somebody wants to play with getting messages using QM+C#+ImapX library.

Macro C# receive email
Code:
Copy      Help
;This macro uses ImapX .NET library. Download it from http://imapx.codeplex.com/ and extract ImapX.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("" "me@gmail.com" password "ALL" 0)
;info:
;Replace 0 to 1 to mark the messages as seen.
;Replace "ALL" to "UNSEEN" to get only unseen messages.
;All search filters: https://tools.ietf.org/html/rfc3501#section-6.4.4
;The function does not delete messages on the server. You can modify it to delete or move to another folder from Inbox. Also you can modify it to get messages from another folder etc.
;ImapX has only some basic documentation: http://imapx.codeplex.com/documentation

;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 ImapX;

public class Email
{
,public static string[] Receive(string user, string password, string filter="ALL", bool markSeen=false)
,{
,,using(var client = new ImapClient("imap.googlemail.com", true)) {
,,,//client.Port=993; client.UseSsl=true; //default
,,,if(!client.Connect()) { Out("failed to connect"); return null; }
,,,if(!client.Login(user, password)) { Out("failed to login"); return null; }
,,,var folder = client.Folders.Inbox;
,,,List<string> a = new List<string>();
,,,foreach(var m in folder.Search(filter, ImapX.Enums.MessageFetchMode.Tiny)) {
,,,,//Out(m.From);
,,,,if(markSeen) m.Seen = true;
,,,,//a.Add(m.ToEml());
,,,,a.Add(m.DownloadRawMessage());
,,,}
,,,return a.ToArray();
,,}
,}
,
,static void Out(object s) { Console.WriteLine(s); }
}
#28
Thanks
#29
I'm trying with OpenPop.NET:

sourceforge.net/projects/hpop/
github.com/foens/hpop
...
#30
or with Mailkit...:
nuget.org/packages/MailKit
github.com/jstedfast/MailKit
mimekit.net


Forum Jump:


Users browsing this thread: 1 Guest(s)