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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
| *!* Yahoo ÇALIŞIYOR
*******************************
*!* Example of using SendViaBLAT
*******************************
#DEFINE PRIORITYHIGH 1
#DEFINE PRIORITYLOW 0
DIMENSION aryAttach(2)
aryAttach(1) = "C:\Test1.txt" && change to an actual file that exists on your computer
aryAttach(2) = "C:\Test2.txt" && change to an actual file that exists on your computer
LOCAL lcFrom, lcTo, lcSubject, lcBody, lcCC, lcBCC, lcMailServer, lcUserName, lcPassword, lnPort, lnPriority, llHTMLFormat, lcErrReturn
lcFrom = "ugurlu2001#yahoo;com"
lcTo = "ugurlu2001#hotmail;com"
lcSubject = "Deneme konusu!"
*!* Sending the body in HTML format
llHTMLFormat = .T. && change to .F. to send plain text message
lcBody = "<a href='http://www.fox4um.com'>" + ;
"Deneme icin yollandi!" + ;
"</a>"
lcCC = "ugurlu2001#gmail;com"
lcBCC = "ugurlu2001#yahoo;com"
lcMailServer = "smtp.mail.yahoo.com" && my SMTP Server
lnPort = 25 && or 587 or 995 default SMTP Server port
lcUserName = "ugurlu2001#yahoo;com" && my SMTP username
lcPassword = "xxxxxxxxxxxx/" && my SMTP password
lnPriority = PRIORITYHIGH
SendViaBLAT(@lcErrReturn, lcFrom, lcTo, lcSubject, lcBody, @aryAttach, lcCC, lcBCC, lcMailServer, lnPort, lcUserName, lcPassword, lnPriority, llHTMLFormat)
IF EMPTY(lcErrReturn)
MESSAGEBOX("'" + lcSubject + "' sent successfullly.", 64, "Send email via BLAT")
ELSE
MESSAGEBOX("'" + lcSubject + "' failed to be sent. Reason:" + CHR(13) + lcErrReturn, 64, "Send email via BLAT")
ENDIF
*******************************************
PROCEDURE SendViaBLAT(tcReturn, tcFrom, tcTo, tcSubject, tcBody, taFiles, tcCC, tcBCC, tcMailServer, tnPort, tcUserName, tcPassword, tnPriority, tlHTMLFormat)
*******************************************
LOCAL lcBlatParam, lcBodyFile, lnCountAttachments, lnResult, loError as Exception
lcBodyFile = ""
TRY
*!* Include full path in Declare, such as "C:\Blat240\full\blat.dll"
*!* or make sure that blat.dll is included in the system's PATH variable
DECLARE INTEGER Send IN "O:\F_Kullan\Blat\blat262.full\blat262\full\blat.dll" STRING cParam
lcBodyFile = ADDBS(SYS(2023)) + SYS(2015) + ".txt"
STRTOFILE(tcBody, lcBodyFile, 0) && body is placed in a text file to be sent by BLAT
lcBlatParam = GetShortPath(lcBodyFile)
IF TYPE("tcTo") = "C"
lcBlatParam = lcBlatParam + " -to " + ALLTRIM(tcTo)
ENDIF
IF TYPE("tcFrom") = "C"
lcBlatParam = lcBlatParam + " -f " + ALLTRIM(tcFrom)
ENDIF
IF TYPE("tcCC") = "C"
lcBlatParam = lcBlatParam + " -cc " + ALLTRIM(tcCC)
ENDIF
IF TYPE("tcBCC") = "C"
lcBlatParam = lcBlatParam + " -bcc " + ALLTRIM(tcBCC)
ENDIF
IF TYPE("tcSubject") = "C"
lcBlatParam = lcBlatParam + [ -s "] + ALLTRIM(tcSubject) + ["]
ENDIF
IF TYPE("tcMailserver") = "C"
lcBlatParam = lcBlatParam + " -server " + ALLTRIM(tcMailserver)
ENDIF
IF TYPE("tnPort") = "N"
lcBlatParam = lcBlatParam + ":" + TRANSFORM(tnPort)
ENDIF
IF TYPE("tcUsername") = "C"
lcBlatParam = lcBlatParam + " -u " + ALLTRIM(tcUsername)
ENDIF
IF TYPE("tcPassword") = "C"
lcBlatParam = lcBlatParam + " -pw " + ALLTRIM(tcPassword)
ENDIF
IF TYPE("tnPriority") = "N" AND BETWEEN(tnPriority, 0, 1)
lcBlatParam = lcBlatParam + " -priority " + TRANSFORM(tnPriority)
ENDIF
IF TYPE("tlHTMLFormat") = "L" AND tlHTMLFormat
lcBlatParam = lcBlatParam + " -html"
ENDIF
IF TYPE("taFiles", 1) = "A"
lcBlatParam = lcBlatParam + " -attach "
FOR lnCountAttachments = 1 TO ALEN(taFiles)
lcBlatParam = lcBlatParam + GetShortPath(ALLTRIM(taFiles(lnCountAttachments))) + ","
ENDFOR
lcBlatParam = LEFT(lcBlatParam, LEN(lcBlatParam) - 1) && Remove Extra Comma
ENDIF
lnResult = Send(ALLTRIM(lcBlatParam))
IF lnResult != 0
DO CASE
CASE lnResult = -2
THROW "The server actively denied our connection./The mail server doesn't like the sender name. "
CASE lnResult = -1
THROW "Unable to open SMTP socket" OR ;
"SMTP get line did not return 220" OR ;
"command unable to write to socket" OR ;
"Server does not like To: address" OR ;
"Mail server error accepting message data."
CASE lnResult = 1
THROW "File name (message text) not given" OR ;
"Bad argument given"
CASE lnResult = 2
THROW "File (message text) does not exist"
CASE lnResult = 3
THROW "Error reading the file (message text) or attached file"
CASE lnResult = 4
THROW "File (message text) not of type FILE_TYPE_DISK "
CASE lnResult = 5
THROW "Error Reading File (message text)"
CASE lnResult = 12
THROW "-server or -f options not specified and not found in registry"
CASE lnResult = 13
THROW "Error opening temporary file in temp directory"
OTHERWISE
THROW "Unknown Error"
ENDCASE
ENDIF
CATCH TO loError
tcReturn = [Error: ] + STR(loError.ERRORNO) + CHR(13) + ;
[LineNo: ] + STR(loError.LINENO) + CHR(13) + ;
[Message: ] + loError.MESSAGE + CHR(13) + ;
[Procedure: ] + loError.PROCEDURE + CHR(13) + ;
[Details: ] + loError.DETAILS + CHR(13) + ;
[StackLevel: ] + STR(loError.STACKLEVEL) + CHR(13) + ;
[LineContents: ] + loError.LINECONTENTS
FINALLY
CLEAR DLLS "Send"
IF FILE(lcBodyFile)
ERASE (lcBodyFile)
ENDIF
ENDTRY
ENDPROC
****************************************
Function GetShortPath
****************************************
LPARAMETERS lcFileName
LOCAL lnReturn, lcBuffer
Declare Integer GetShortPathNameA In Win32API As GetShortPathName String, String, Integer
lcBuffer = SPACE(255)
lnReturn= GetShortPathName(lcFileName, @lcBuffer, 255)
Clear Dlls "GetShortPathName"
Return (Left(lcBuffer, lnReturn))
ENDFUNC |