Hi again :)

Here's a piece of code I wrote for a customer. It receives some parameters
(self explanatory) and sends the mail. In my scenario there was only one
attachment at most. If you need to add multiple attachments you may need to
call the piece of code that starts with "*-- get the attachment's short
name" multiple times, but it's up to you.

All I can tell is this routine never failed on me. I hope it will do the
same for you.

*---------------------------------
Lparameters ;
 tcBodyText, ;
 tcTOEmailAddress, ;
 tcCCEmailAddress, ;
 tcSubject, ;
 tcAttachmentFileName, ;
 tcMailServer, ;
 tnPort, ;
 tcFromEmailAddress, ;
 tcUserName, ;
 tcPassword

Local lcParameterString As String

*-- Declare the API functions.
Declare Integer Send ;
 In blat.dll ;
 String cParam

Declare Integer GetShortPathNameA ;
 In Win32API As GetShortPathName ;
 String, ;
 String, ;
 Integer

*-- create the parameter string variable:
lcParameterString = ""

*-- create the message body
lcBodyFileName = "_" + Right(Sys(2015),7)
StrToFile(tcBodyText,lcBodyFileName,0)
lcBodyFileName = FullPath(lcBodyFileName)

*-- get the short (msdos) file name (required by blat)
lcBuffer = Space(255)
lnReturn = GetShortPathName(lcBodyFileName, @lcBuffer,255)
lcBodyFileShortName = Left(lcBuffer,lnReturn)

*-- store the shortfilename into parameter string
lcParameterString = lcBodyFileShortName + " " && careful with the spaces. 
One single extra space and blat fails.

*-- add TO address to parameter string
lcParameterString = lcParameterString + "-to " + tcTOEmailAddress + " "

*-- add the CC address to parameter string
If Vartype(tcCCEmailAddress) = "C" And Not Empty(Alltrim(tcCCEmailAddress))
 lcParameterString = lcParameterString + "-cc " + tcCCEmailAddress + " "
EndIf

*-- add the subject to parameter string:
If Vartype(tcSubject) <> "C" Or ;
  Empty(Alltrim(tcSubject))
 tcSubject = "Automated email from UPC Maintenance process"
EndIf
lcParameterString = lcParameterString + "-subject " + tcSubject + " "

*-- get the attachment's short (msdos) filename
If Vartype(tcAttachmentFileName) = "C" And Not Empty(tcAttachmentFileName)
 lcBuffer = Space(255)
 lnReturn = GetShortPathName(tcAttachmentFileName, @lcBuffer,255)
 lcAttachmentFileShortName = Left(lcBuffer,lnReturn)
 *-- and add it to parameter string:
 lcParameterString = lcParameterString + "-attach " + 
lcAttachmentFileShortName + " "
EndIf

*-- get the mail server:
If Vartype(tcMailServer) = "C" And Not Empty(tcMailServer)
 lcParameterString = lcParameterString + "-server " + Alltrim(tcMailServer) 
+ " "
Else
 ThisForm.Log("Error. Mail server not defined.")
 Return .F.
EndIf

*-- add the port to string parameter:
lcParameterString = lcParameterString + "-port " + Transform(tnPort) + " "

*-- add the "FROM" email address:
lcParameterString = lcParameterString + "-f " + tcFromEmailAddress + " "

*-- Add the smtp username:
lcParameterString = lcParameterString + "-u " + tcUserName + " "

*-- add the smtp password:
lcParameterString = lcParameterString + "-pw " + tcPassword

lnResult = Send(lcParameterString)

If lnResult = 0
 ThisForm.Log("    Mail to " + tcTOEmailAddress + " was sent succesfully.")
Else
 ThisForm.Log("    Error sending email to " + tcTOEmailAddress + ". Error 
code is " + Transform(lnResult))
 ThisForm.Log("    BLAT.DLL parameter: " + lcParameterString)
 ThisForm.Log("    If you see this error in the activity log file, please 
forward the report email to [EMAIL PROTECTED]")
EndIf
*-----------------
----- Original Message ----- 
From: "MB Software Solutions" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, May 30, 2007 4:10 PM
Subject: Re: What's wrong with this BLAT string?


> Grigore Dolghin wrote:
>> Make sure you don't have two consecutive spaces anywhere.
>>
> That would cause it to fail?  Also, must I wrap directory/folder
> locations in quotes for scenarios where it's "Documents and
> Settings\Mike\MyFile.txt"  ??
>
>
> -- 
> Michael J. Babcock, MCP
> MB Software Solutions, LLC
> http://mbsoftwaresolutions.com
> http://fabmate.com
> "Work smarter, not harder, with MBSS custom software solutions!"
>
>
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to