AHK: Sending Email Issue - autohotkey

I use below code to send email using AHK. It works when I use literal strings in subject and message body. But when I try to use %variable%, the resultant email received has blank subject/message body.
Order :=
Order = %Order% `n FAX MESSAGE
Order = %Order% `n
Order = %Order% `n Sent: %DateString% %TimeString%
pmsg := ComObjCreate("CDO.Message")
pmsg.From := """Lens Shapers"" <fax#l******s.com>"
pmsg.To := "k*******r#gmail.com"
pmsg.BCC := ""
pmsg.CC := ""
pmsg.Subject := "Lenses are Ready" **;THIS SUBJECT IS TRANSMITTED GOOD**
pmsg.TextBody := %Order% **;THIS MESSAGE BODY IS BLANK WHEN EMAIL IS RECEIVED**
sAttach := ""
fields := Object()
fields.smtpserver := "smtp.gmail.com" ; specify your SMTP server
fields.smtpserverport := 465 ; 25
fields.smtpusessl := True ; False
fields.sendusing := 2 ; cdoSendUsingPort
fields.smtpauthenticate := 1 ; cdoBasic
fields.sendusername := "k*****f#l******s.com"
fields.sendpassword := "PASSWORD"
fields.smtpconnectiontimeout := 60
schema := "http://schemas.microsoft.com/cdo/configuration/"
pfld := pmsg.Configuration.Fields
For field,value in fields
pfld.Item(schema . field) := value
pfld.Update()
Loop, Parse, sAttach, |, %A_Space%%A_Tab%
pmsg.AddAttachment(A_LoopField)
pmsg.Send()

It should work, but when you use a variable in an expression, you don't use the %'s and when you use ":=" that is an assignment of an expression. So try:
pmsg.TextBody := Order
As that should work. If you also need text elements, you need to use quotes around literals and the dot concatenation:
pmsg.TextBody := "Order: " . Order . "`n`n" ; also follows with 2 new lines
Hth,

Related

Create auto hot key script that copies file paths onto clipboard as python styled list

I would like to create an autohotkey script that produces a python styled list when copying multiple filepaths in explorer.
E.g If I had three files within the C directory like below:
Then pressing the ahk shortcut should copy the following paths to my clipboard in the below style:
["C:\a.txt","C:\b.txt","C:\c.txt"]
However if a single filepath is selected I'd prefer for it to remain in a string format when copied onto the clipboard e.g copying 'a.txt' should copy the path to my clipboard as:
"C:\a.txt"
I've tried to generate my own ahk shortcut but keep getting errors when I try to manipulate the clipboard:
#c::
Send ^c
ClipWait
Clipboard:= Clipboard ""
temp := Clipboard
paths := StrSplit(temp, "`r`n")
num_paths := paths.MaxIndex()
if (num_paths == 1)
{
Clipboard:= `".Clipboard.`"
Return
}
Array := []
For path in paths
{
path := `".path.`"
Array.push(path)
}
Clipboard:= Array ""
Return
Any help fixing this shortcut would be appreciated.
Had to read up a bit on ahk syntax but I figured it out in the end.
Here's my working shortcut:
#c::
Clipboard := ""
Send, ^c
ClipWait , 2
Clipboard:= Clipboard . ""
temp := Clipboard
paths := StrSplit(temp, "`r`n")
num_paths := paths.MaxIndex()
if (num_paths == 1)
{
Clipboard:= "'" . temp . "'"
Return
}
output_string := "["
For key,path in paths
{
path := "'" . path . "'"
output_string := output_string . path . ", "
}
StringTrimRight, output_string, output_string, 2
output_string := output_string . "]"
Clipboard:= output_string
Return
#c::
Send ^c
Email
Email:= Email ""
temp := Email
paths := StrSplit(temp, "`r`n")
num_paths := paths.MaxIndex()
if (num_paths == 1)
{
Email:= `".Email.`"
Return
}

How can I implement u^k = M^k u_0?

Let M := Matrix([[0.94, 0.09], [0.06, 0.91]]); and u[0] = Vector([0.8, 0.2]);. What command could I use to get u^k = M^k u_0 for k=5, 10, ..., 50?
I'm guessing you mistyped, and you want to call the result of M^k . u[0] as u[k] rather than (as you wrote it) u^k.
restart;
with(LinearAlgebra):
M := Matrix([[0.94, 0.09], [0.06, 0.91]]):
u[0] := Vector([0.8, 0.2]):
# One (inefficient) way
seq(M^k . u[0],k=5..50,5);
# Another way
M5 := M^5:
for k from 5 to 50 by 5 do
u[k] := M5 . u[k-5];
end do;
# Another way
(evals,evecs) := simplify([Eigenvectors(M)])[]:
seq(evecs . DiagonalMatrix(map(`^`,evals,k))
. evecs^(-1).u[0],
k=5..50,5);

How to translate CURL command to Delphi

I'm trying to use Delphi 10.2 TREST components with AWS. I have a CURL command that works:
curl -X POST --data #GetIDData.json -H "X-Amz-Target: AWSCognitoIdentityService.GetId" -H "Content-Type: application/x-amz-json-1.1" https://cognito-identity.us-east-1.amazonaws.com/
GetIDData.json contains this:
{"IdentityPoolId":"us-east-1:XXXXXXXXXXXXXXXXXXXXX"}
Successful result is this:
{"IdentityId":"us-east-1:XXXXXXXXXXXXXXXXXXXXX"}
I'd like to duplicate that result using Delphi TREST components:
...
fClient := TRESTClient.Create('https://cognito-identity.us-east-1.amazonaws.com/');
fClient.SetHTTPHeader('Content-Type', 'application/x-amz-json-1.1');
fClient.SetHTTPHeader('X-Amz-Target', 'AWSCognitoIdentityService.GetId');
fRequest := TRESTRequest.Create(nil);
fRequest.Client := fClient;
fRequest.Method := TRESTRequestMethod.rmPOST;
// fRequest.AddBody('{"IdentityPoolId":"us-east-1:XXXXXXXXXXXXXXXXXXXXX"}', ctAPPLICATION_JSON);
lJObj := TJSONObject.Create;
lJObj.AddPair('IdentityPoolId', 'us-east-1:XXXXXXXXXXXXXXXXXXXXX');
fRequest.AddBody(lJObj);
fRequest.Execute;
str := fRequest.Response.Content;
...
But the result is an error:
{"Output":"__type":"com.amazon.coral.service#UnknownOperationException","message":null},"Version":"1.0"}
Downloading OpenSSL and putting the dlls into System32 did not help.
Can anyone tell me what I'm doing wrong?
This works:
...
lClient := TRESTClient.Create('https://cognito-identity.us-east-1.amazonaws.com/');
lRequest := TRESTRequest.Create(nil);
lRequest.Client := lClient;
lRequest.Method := TRESTRequestMethod.rmPOST;
lParam := lRequest.Params.AddItem;
lParam.name := 'X-Amz-Target';
lParam.Value := 'AWSCognitoIdentityService.GetId';
lParam.ContentType := ctNone;
lParam.Kind := pkHTTPHEADER;
lParam := lRequest.Params.AddItem;
lParam.name := 'Content-Type';
lParam.Value := 'application/x-amz-json-1.1';
lParam.ContentType := ctNone;
lParam.Kind := pkHTTPHEADER;
lParam.Options := [poDoNotEncode];
lRequest.AddBody('{"IdentityPoolId":"us-east-1:XXXXXXXXXXXXXXXXXXXXX"}', ctAPPLICATION_JSON);
lRequest.Execute;
...
WireShark was not as helpful as I wanted because its doc is out of date and I'm using encryption. But the website mentioned by #Christophe Morio in this post made finding a solution a piece of cake.

Unsecured login error when sending email (Gmail) using AutoHotkey

Is there a better login method in AutoHotkey to do this? Or perhaps a way to allow unsecured logins to Google? I have enabled less secure apps on the Google account settings.
AutoHotkey error:
This message could not be sent to SMTP server. The transport error codwe was 0x80040217. The server response was not available.
Gmail response (some info redacted):
Sign-in attempt prevented
Hi [redacted],
Someone just tried to sign in to your Google Account [redacted]#gmail.com from an app that doesn't meet modern security standards.
...
AutoHotkey script (some info redacted):
pmsg := ComObjCreate("CDO.Message")
pmsg.From := """John Doe"" <John.Doe#gmail.com>"
pmsg.To := "Jane.Doe#gmail.com, Joe.Schmo#gmx.com"
pmsg.BCC := "" ; Blind Carbon Copy, Invisible for all, same syntax as CC
pmsg.CC := "redacted#gmail.com" ; Somebody#somewhere.com, Other-somebody#somewhere.com
pmsg.Subject := "See below"
;pmsg.TextBody := ""
pmsg.HtmlBody := "<html><head><title>Hello</title></head><body><table border='1'><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table> </body></html>"
;sAttach := "" ; can add multiple attachments, the delimiter is |
fields := Object()
fields.smtpserver := "smtp.gmail.com" ; specify your SMTP server
fields.smtpserverport := 465 ; 25
fields.smtpusessl := True ; False
fields.sendusing := 2 ; cdoSendUsingPort
fields.smtpauthenticate := 1 ; cdoBasic
fields.sendusername := "redacted#gmail.com"
fields.sendpassword := "redacted"
fields.smtpconnectiontimeout := 60
schema := "http://schemas.microsoft.com/cdo/configuration/"
pfld := pmsg.Configuration.Fields
For field,value in fields
pfld.Item(schema . field) := value
pfld.Update()
Loop, Parse, sAttach, |, %A_Space%%A_Tab%
pmsg.AddAttachment(A_LoopField)
pmsg.Send()
return
Hmm, maybe you need the quotes around the formed schema-field:
pfld.Item("""" . schema . field . """") := value
Or try '"' to get the quotes.
Also, try port 25 and/or username w/o the #gmail part (but I think what you have is correct for gmail).
Hth,

Console application via network in eiffel?

Hey I'm working in project, but i cant manage to connect from a IP not located in the same network (LAN). The code bellow works fine locally, but I cant figure out how to make work from different IP located in different locations?, and google cant see to help, any ideas?
class
RG_NETWORK_SERVER
inherit
STORABLE
NETWORK_SERVER
redefine
receive,
received,
close
end
create
make_server
feature
connections: LINKED_LIST [RG_CONNECTION]
max_to_poll: INTEGER
message_out: RG_MESSAGE
received: detachable RG_MESSAGE
poll: MEDIUM_POLLER
make_server
require
local
l_message_out: detachable like message_out
l_connections: detachable like connections
l_in: detachable like in
do
make (1337)
max_to_poll := 1
create poll.make_read_only
in.set_non_blocking
l_in := in
create l_message_out.make
message_out := l_message_out
create l_connections.make
connections := l_connections
connections.compare_objects
execute
end
process_message
local
stop: BOOLEAN
pos: INTEGER
do
from
connections.start
until
connections.after or stop
loop
if connections.item.is_waiting then
if attached {RG_MESSAGE} retrieved (connections.item.active_medium) as l_message_in then
if l_message_in.new then
connections.item.set_client_name (l_message_in.client_name)
create message_out.make
message_out.set_client_name (l_message_in.client_name)
message_out.extend (l_message_in.client_name)
message_out.extend (" has just joined the server%N")
elseif l_message_in.over then
poll.remove_associated_read_command (connections.item.active_medium)
connections.remove
create message_out.make
message_out.set_client_name (l_message_in.client_name)
message_out.extend (l_message_in.client_name)
message_out.extend (" has just gone%N")
stop := True
else
message_out := l_message_in.deep_twin
message_out.put_front (" has just sent that :%N")
message_out.put_front (message_out.client_name)
message_out.put_front ("-> ")
end
pos := connections.index
-- l_message_in.print_message
message_out.print_message
broadcast
connections.go_i_th (pos)
-- Post status to client
create message_out.make
message_out.extend ("Got it! %N")
message_out.independent_store (connections.item.active_medium)
end
end
if not stop then
connections.forth
end
end
end
broadcast
local
client_name: detachable STRING
do
client_name := message_out.client_name
if client_name /= Void then
from
connections.start
until
connections.after
loop
if connections.item.client_name /~ client_name then
message_out.independent_store (connections.item.active_medium)
end
connections.forth
end
end
end
receive
do
in.accept
if attached {like outflow} in.accepted as l_outflow then
l_outflow.set_blocking
new_client (l_outflow)
end
from
connections.start
until
connections.after
loop
connections.item.initialize
connections.forth
end
poll.execute (max_to_poll, 1000)
end
new_client (a_flow: attached like outflow)
local
new_connection: RG_CONNECTION
do
if max_to_poll <= a_flow.descriptor then
max_to_poll := a_flow.descriptor + 1
end
create new_connection.make (a_flow)
connections.extend (new_connection)
create message_out.make
message_out.extend ("Welcome! %N")
message_out.independent_store (a_flow)
poll.put_read_command (new_connection)
end
end
and the client:
class
RG_NETWORK_CLIENT
inherit
NETWORK_CLIENT
redefine
received
end
create
make_join
feature
make_join(ip:STRING)
require
is_ip_void : ip /= Void
local
l_client_name: detachable like client_name
do
check_name
l_client_name := client_name
make (1337, ip)
max_to_poll := in_out.descriptor + 1
create connection.make (in_out)
create poll.make_read_only
poll.put_read_command (connection)
send_name_to_server
auto_scan_server
processing
end
feature
connection: RG_CONNECTION
std_input: detachable RG_CONNECTION
message_out: RG_MESSAGE
received: detachable RG_MESSAGE
client_name: STRING
over: BOOLEAN
poll: MEDIUM_POLLER
input_poll: detachable MEDIUM_POLLER
max_to_poll: INTEGER
waiting:BOOLEAN
send_name_to_server
do
create message_out.make
message_out.set_client_name (client_name)
message_out.set_new (True)
message_out.set_over (False)
send (message_out)
end
processing
do
from
over := False
until
over
loop
scan_from_server
if not over then
read_content
end
end
cleanup
end
read_content
local
temp: detachable STRING
do
io.put_string ("Enter message: ")
io.readline
temp := io.laststring
if temp /= Void and not temp.is_empty then
if temp.is_equal ("bye") then
over := True
end
create message_out.make
message_out.extend (temp)
message_out.extend ("%N")
message_out.set_over (over)
message_out.set_client_name (client_name)
message_out.set_new (False)
send (message_out)
auto_scan_server
end
end
check_name
local
l_name: detachable STRING
do
io.putstring ("Enter your name : ")
io.readline
l_name := io.laststring
check
l_name_attached: l_name /= Void
end
client_name := l_name.twin
end
scan_from_server
local
l_received: like received
do
connection.initialize
poll.execute (max_to_poll, 1000)
if connection.is_waiting then
receive
l_received := received
if l_received /= Void then
waiting := FALSE
l_received.print_message
if l_received.over then
over := True
end
end
end
end
auto_scan_server
do
waiting := True
from until not waiting
loop
scan_from_server
end
end
end
The work around is the work with the samples provided from Eiffel, it works as longest the two persons are connected in the same network. for example as follow:
Here we define if the user has receive the message or is waiting for one, also redefine the poll_command to be able to use it.
inherit
POLL_COMMAND
redefine
make
end
create
make
feature {NONE} -- Initialization
make (s: IO_MEDIUM)
do
Precursor (s)
create client_name.make_empty
end
feature
is_waiting: BOOLEAN
client_name: STRING
execute (arg: ANY)
do
is_waiting := True
end
initialize
do
is_waiting := False
end
set_client_name (s: STRING)
require
s_exists: s /= Void
do
client_name := s.twin
end
end
Then following the chat sample, that can be found in the samples folder, in the message handler, we create the follow:
set_client_name (s: STRING)
require
s_not_void: s /= Void
do
client_name := s.twin
end
set_new (flag: BOOLEAN)
do
new := flag
end
Later in the connection class we are able to connect to a server ip, which it can be pass true command line or via GUI input.
make_join (name: STRING; ip: STRING; gc: RG_CLIENT)
require
is_ip_void: ip /= Void
do
-- Connects to IP on port 1337
make (1337, ip)
max_to_poll := in_out.descriptor + 1
create connection.make (in_out)
create poll.make_read_only
poll.put_read_command (connection)
-- Sets client name and refrence
client_name := name
p_client := gc
-- Sends name to server and receives ID
client_id := send_name_to_server
-- Launches instance as thread
make_thread
launch
execute
end
Then in the server class...
make_server (gs: RG_SERVER)
local
l_message_out: detachable like message_out
l_connections: detachable like connections
l_in: detachable like in
do
-- Instantiate reference and create server listening on port 1337
game_server := gs
make (1337)
max_to_poll := 1
create poll.make_read_only
in.set_non_blocking
l_in := in
create l_connections.make
connections := l_connections
connections.compare_objects
-- Launches instance as tread
make_thread
launch
end
There is a bit more code, but this is a good sample in how to do it, there must be a method to handle the connections, but this is a good start, also remember that all this is based on their samples, chat sample is a good point of start..
enjoy eiffel while is not crashing .