-
Notifications
You must be signed in to change notification settings - Fork 71
/
SendEmail.ahk
102 lines (81 loc) · 3.7 KB
/
SendEmail.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
SendEmail(p_to, p_From, p_subject, p_message, oAttachments := "", user="[email protected]", pass="asvhaf32489hjk")
{ ; username '@adam.com.au' isn't required to receive emails, but it is to SEND!
SMTP := "mail.adam.com.au"
port := 25
if (!p_From || isValidEmail(p_From)) ; if user puts a weird name function will fail with an error! hence check if valid
p_From := "[email protected]" ; Not a Real Address! """AHKUser"" <[email protected]>"
; note [email protected] fails but [email protected] works
getSystemTimerResolutions(MinTimer, MaxTimer)
p_message .= "`n`n`n`n"
. "================================================================ `n"
. debugData()
if (oAttachments && isobject(oAttachments))
{
for index, attachmentPath in oAttachments
sAttach .= attachmentPath ","
}
else if oAttachments
sAttach := oAttachments
sAttach := Trim(sAttach, "`t `,")
email_string := "-f " p_From " -server " SMTP " -port " port " -t " p_to
. " -s """ p_subject """ -body """ p_message """ -u " user " -pw " pass
sAttach ? email_string .= " -attach """ sAttach """"
; inlcude the DLL inside exe
If 0
FileInstall, Included Files\email\blat.dll, Ignore this param
hBlatt := A_IsCompiled ? ResourceLoadLibrary("blatt.dll") : MemoryLoadLibrary("Included Files\email\blat.dll")
BlattSend := MemoryGetProcAddress(hBlatt,"Send" (A_IsUnicode?"W":"A"))
DllCall(BlattSend, "Str", email_string)
MemoryFreeLibrary(hBlatt)
;msgbox % i " " errorlevel "`n" email_string
return
}
/* Com Method
SendEmail(p_to, p_From, p_subject, p_message, oAttachments := "", user="[email protected]", pass="asvhaf32489hjk")
{ ; username '@adam.com.au' isn't required to receive emails, but it is to SEND!
; gmail
; user="[email protected]", pass="PublicPasswordfwnk322rf28932hjf32809"
pmsg := ComObjCreate("CDO.Message")
if (p_From && isValidEmail(p_From)) ; if user puts a weird name function will fail with an error! hence check if valid
pmsg.From := p_From ; i.e. an address which violates email address rules
else pmsg.From := "[email protected]" ; Not a Real Address! """AHKUser"" <[email protected]>"
pmsg.To := p_to
pmsg.BCC := "" ; Blind Carbon Copy, Invisable for all, same syntax as CC
pmsg.CC := "" ; "[email protected], [email protected]"
pmsg.Subject := p_subject
;You can use either Text or HTML body like
getSystemTimerResolutions(MinTimer, MaxTimer)
p_message .= "`n`n`n`n"
. "================================================================ `n"
. debugData()
pmsg.TextBody := p_message
;OR
;pmsg.HtmlBody := "<html><head><title >Hello</title></head><body><h2>Hello</h2><br /><p>Testing!</p></body></html>"
;sAttach := "Path_Of_Attachment" ; can add multiple attachments, the delimiter is |
if (oAttachments && isobject(oAttachments))
{
for index, attachmentPath in oAttachments
sAttach .= attachmentPath "|"
}
else if oAttachments
sAttach := oAttachments
sAttach := Trim(sAttach, "`t |")
fields := Object()
fields.smtpserver := "securemail.adam.com.au" ;"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 := user
fields.sendpassword := pass
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()
}
*/