Good Morning all,
Have been using Blat here at work for years. Essentially modifying the code as the need arose. now have a client that I would like to use it on, but for some reason it always returns a code 1 in the new environment but works fine here at work...
Would someone please look at the sample below to see what I might be missing?
LPARAMETERS lcsubject, lcbody, lcrecipient, lcfrom, lccopyto
lcFrom = 'dlloyd@wow.com'
*lcfrom = 'dlloyd@test.com'
lcSubject = 'Email Test'
set Safety off
lcBody = 'This is a Test of an automated email system. Third Test. Would you Please reply if received'+ CHR(13) + CHR(10) + CHR(13) + CHR(10)
lcRecipient = 'desmond.lloyd@gmail.com'
STRTOFILE(lcbody, "Body.txt")
lcstring = 'C:\Body.txt -s "' + lcsubject + '" -to ' + lcrecipient + ' -f ' + lcfrom + ' -u '+'dlloyd'+' -pw '+'password'+ ' -server '+'192.168.999..62'
dll_name = "blat.dll"
DECLARE INTEGER Send in &dll_name STRING blatstring
lnresult = send(lcstring)
IF lnresult > 0
wait window 'Result: '+alltrim(str(lnREsult))
ENDIF
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html ---
Desmond,
from my program I use to send email via blat the error you are getting back is "File name (message text) not given or Bad argument given":
Here is my full code in my EmailViaBlat.prg, maybe you can try it with your stuff and see if there is any difference:
LPARAMETERS tcReturn, tcFrom, tcTo, tcSubject, tcBody, taFiles, tcCC, tcBCC, tcMailServer, tnPort, tcUserName, tcPassword, tnPriority, tlHTMLFormat) ******************************************* LOCAL lcBlatParam, lcBodyFile, lnCountAttachments, lnResult, loError as Exception
m.lcBlatParam = m.lcBodyFile &&GetShortPath(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 "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(m.lcBlatParam) + IIF(oAppinfo.BlatLog, " -log blat.log -debug", ""))
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
Frank.
Frank Cazabon
On 28/06/2018 01:31 PM, Desmond Lloyd wrote:
Good Morning all,
Have been using Blat here at work for years. Essentially modifying the code as the need arose. now have a client that I would like to use it on, but for some reason it always returns a code 1 in the new environment but works fine here at work...
Would someone please look at the sample below to see what I might be missing?
LPARAMETERS lcsubject, lcbody, lcrecipient, lcfrom, lccopyto
lcFrom = 'dlloyd@wow.com'
*lcfrom = 'dlloyd@test.com'
lcSubject = 'Email Test'
set Safety off
lcBody = 'This is a Test of an automated email system. Third Test. Would you Please reply if received'+ CHR(13) + CHR(10) + CHR(13) + CHR(10)
lcRecipient = 'desmond.lloyd@gmail.com'
STRTOFILE(lcbody, "Body.txt")
lcstring = 'C:\Body.txt -s "' + lcsubject + '" -to ' + lcrecipient + ' -f '
- lcfrom + ' -u '+'dlloyd'+' -pw '+'password'+ ' -server '+'192.168.999..62'
dll_name = "blat.dll"
DECLARE INTEGER Send in &dll_name STRING blatstring
lnresult = send(lcstring)
IF lnresult > 0
wait window 'Result: '+alltrim(str(lnREsult))
ENDIF
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]
Thank you, will give this a try....
Regards, Desmond
On Thu, 28 Jun 2018 at 12:39, Frank Cazabon frank.cazabon@gmail.com wrote:
Desmond,
from my program I use to send email via blat the error you are getting back is "File name (message text) not given or Bad argument given":
Here is my full code in my EmailViaBlat.prg, maybe you can try it with your stuff and see if there is any difference:
LPARAMETERS tcReturn, tcFrom, tcTo, tcSubject, tcBody, taFiles, tcCC, tcBCC, tcMailServer, tnPort, tcUserName, tcPassword, tnPriority, tlHTMLFormat)
LOCAL lcBlatParam, lcBodyFile, lnCountAttachments, lnResult, loError as Exception
m.lcBlatParam = m.lcBodyFile &&GetShortPath(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 "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(m.lcBlatParam) + IIF(oAppinfo.BlatLog, " -log blat.log -debug", ""))
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
Frank.
Frank Cazabon
On 28/06/2018 01:31 PM, Desmond Lloyd wrote:
Good Morning all,
Have been using Blat here at work for years. Essentially modifying the code as the need arose. now have a client that I would like to use it
on,
but for some reason it always returns a code 1 in the new environment but works fine here at work...
Would someone please look at the sample below to see what I might be missing?
LPARAMETERS lcsubject, lcbody, lcrecipient, lcfrom, lccopyto
lcFrom = 'dlloyd@wow.com'
*lcfrom = 'dlloyd@test.com'
lcSubject = 'Email Test'
set Safety off
lcBody = 'This is a Test of an automated email system. Third Test. Would you Please reply if received'+ CHR(13) + CHR(10) + CHR(13) + CHR(10)
lcRecipient = 'desmond.lloyd@gmail.com'
STRTOFILE(lcbody, "Body.txt")
lcstring = 'C:\Body.txt -s "' + lcsubject + '" -to ' + lcrecipient + '
-f '
- lcfrom + ' -u '+'dlloyd'+' -pw '+'password'+ ' -server
'+'192.168.999..62'
dll_name = "blat.dll"
DECLARE INTEGER Send in &dll_name STRING blatstring
lnresult = send(lcstring)
IF lnresult > 0
wait window 'Result: '+alltrim(str(lnREsult))
ENDIF
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]
I often used the BLAT.EXE to debug email sending, as each ISP seems to have slightly different interpretations of what is required to logon in username (dloyd or dloyd@isp.com) and ports and AUTH LOGIN vs. username. With the -debug and new -superdebug options, you can get a verbose text file that gives you some clues on what you might need to set up.
Then you can cycle through the variations of this: http://www.blat.net/syntax/syntax.html
If the client is already using this ISP for their email, it can be helpful to review the settings of one of their mail clients.
ISPs *usually* post their email client settings somewhere on their support site, and these can provide valuable clues. You might discover you need to use TLS or a non-standard port in order to connect.
On Thu, Jun 28, 2018 at 1:31 PM, Desmond Lloyd desmond.lloyd@gmail.com wrote:
Good Morning all,
Have been using Blat here at work for years. Essentially modifying the code as the need arose. now have a client that I would like to use it on, but for some reason it always returns a code 1 in the new environment but works fine here at work...
Would someone please look at the sample below to see what I might be missing?
LPARAMETERS lcsubject, lcbody, lcrecipient, lcfrom, lccopyto
lcFrom = 'dlloyd@wow.com'
*lcfrom = 'dlloyd@test.com'
lcSubject = 'Email Test'
set Safety off
lcBody = 'This is a Test of an automated email system. Third Test. Would you Please reply if received'+ CHR(13) + CHR(10) + CHR(13) + CHR(10)
lcRecipient = 'desmond.lloyd@gmail.com'
STRTOFILE(lcbody, "Body.txt")
lcstring = 'C:\Body.txt -s "' + lcsubject + '" -to ' + lcrecipient + ' -f '
- lcfrom + ' -u '+'dlloyd'+' -pw '+'password'+ ' -server '+'192.168.999..62'
dll_name = "blat.dll"
DECLARE INTEGER Send in &dll_name STRING blatstring
lnresult = send(lcstring)
IF lnresult > 0
wait window 'Result: '+alltrim(str(lnREsult))
ENDIF
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]
Hi,
I see 2 things:
1) Macrosubstitution is not needed: (not an error, but error prone sometimes)
DECLARE INTEGER Send in &dll_name STRING blatstring could be: DECLARE INTEGER Send in (dll_name) STRING blatstring
2) Bad capitalization of the function:
lnresult = send(lcstring) should be: lnresult = Send(lcstring)
The capitalization of "Send" (and any DLL function) should be keept in all the code. At least this is a problem with many Win32 API functions, and I apply it for any DLL function.
Other than this: - Could be a permissions problem in the server - ¿Some dependant C++ runtime?
Regards,
Fernando D. Bozzo.-
2018-06-28 19:31 GMT+02:00 Desmond Lloyd desmond.lloyd@gmail.com:
Good Morning all,
Have been using Blat here at work for years. Essentially modifying the code as the need arose. now have a client that I would like to use it on, but for some reason it always returns a code 1 in the new environment but works fine here at work...
Would someone please look at the sample below to see what I might be missing?
LPARAMETERS lcsubject, lcbody, lcrecipient, lcfrom, lccopyto
lcFrom = 'dlloyd@wow.com'
*lcfrom = 'dlloyd@test.com'
lcSubject = 'Email Test'
set Safety off
lcBody = 'This is a Test of an automated email system. Third Test. Would you Please reply if received'+ CHR(13) + CHR(10) + CHR(13) + CHR(10)
lcRecipient = 'desmond.lloyd@gmail.com'
STRTOFILE(lcbody, "Body.txt")
lcstring = 'C:\Body.txt -s "' + lcsubject + '" -to ' + lcrecipient + ' -f '
- lcfrom + ' -u '+'dlloyd'+' -pw '+'password'+ ' -server
'+'192.168.999..62'
dll_name = "blat.dll"
DECLARE INTEGER Send in &dll_name STRING blatstring
lnresult = send(lcstring)
IF lnresult > 0
wait window 'Result: '+alltrim(str(lnREsult))
ENDIF
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]
Use the As AliasName clause when declaring the method in the dll. Then you won't need to deal with case.
From the VFP help:
AS AliasName Specifies an alias name for a shared library function name that has the same name as a Visual FoxPro function or is not a legal Visual FoxPro name. AliasName should not be a Visual FoxPro reserved word or the name of a shared library function already registered with Visual FoxPro.
If you assign alias to the function, use the alias when calling the shared library function. AliasName is not case-sensitive.
HTH, Tracy
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Fernando D. Bozzo Sent: Thursday, June 28, 2018 1:51 PM To: profoxtech@leafe.com Subject: Re: VFP9 and Blat
Hi,
I see 2 things:
1) Macrosubstitution is not needed: (not an error, but error prone sometimes)
DECLARE INTEGER Send in &dll_name STRING blatstring could be: DECLARE INTEGER Send in (dll_name) STRING blatstring
2) Bad capitalization of the function:
lnresult = send(lcstring) should be: lnresult = Send(lcstring)
The capitalization of "Send" (and any DLL function) should be keept in all the code. At least this is a problem with many Win32 API functions, and I apply it for any DLL function.
Other than this: - Could be a permissions problem in the server - ¿Some dependant C++ runtime?
Regards,
Fernando D. Bozzo.-
2018-06-28 19:31 GMT+02:00 Desmond Lloyd desmond.lloyd@gmail.com:
Good Morning all,
Have been using Blat here at work for years. Essentially modifying the code as the need arose. now have a client that I would like to use it on, but for some reason it always returns a code 1 in the new environment but works fine here at work...
Would someone please look at the sample below to see what I might be missing?
LPARAMETERS lcsubject, lcbody, lcrecipient, lcfrom, lccopyto
lcFrom = 'dlloyd@wow.com'
*lcfrom = 'dlloyd@test.com'
lcSubject = 'Email Test'
set Safety off
lcBody = 'This is a Test of an automated email system. Third Test. Would you Please reply if received'+ CHR(13) + CHR(10) + CHR(13) + CHR(10)
lcRecipient = 'desmond.lloyd@gmail.com'
STRTOFILE(lcbody, "Body.txt")
lcstring = 'C:\Body.txt -s "' + lcsubject + '" -to ' + lcrecipient + ' -f '
- lcfrom + ' -u '+'dlloyd'+' -pw '+'password'+ ' -server
'+'192.168.999..62'
dll_name = "blat.dll"
DECLARE INTEGER Send in &dll_name STRING blatstring
lnresult = send(lcstring)
IF lnresult > 0
wait window 'Result: '+alltrim(str(lnREsult))
ENDIF
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html
[excessive quoting removed by server]