From: Geoff Chambers on
I'm looking for some simple code that would read some data from a
table and then send me and email. The email sample was more than what
I was looking for. I don't need any GUI interface, just something
simple that would send an email without user interaction.
From: richard.townsendrose on
Geoff

ITS EASY

just see the sample vo classes, or download something from geoff's
site

what despatcher do you need ?
smtp, groupwise, lotusnotes, or even the dreaded outlook ...
look at marti's mapi classes ... it'll drive almost anything.

steps
a) get the data and package it up
b) send it and report send status.

IF SELF:oDCccEmail:Checked
cMainRecip:=SELF:aNM:FIELDGET(#NAMEREF)
SELF:aNM:GoTop()
DO WHILE ! SELF:aNM:EoF
IF ! SELF:aNM:FIELDGET(#NAMEREF) == cMainRecip
AAdd(aCCS, SELF:aNM:FIELDGET(#NAMEREF))
ENDIF
SELF:aNM:Skip()
ENDDO
SELF:aNm:Seek(cMainRecip)
cFull:='To: ' + AllTrim(LookupNameC(cMainRecip)) + ' of ' +
AllTrim(LookupNameX(cMainRecip)) + CRLF + CRLF + cMsg
oEMail:=EmailSend{{cMainRecip}, AsNameRef, cTitle, cFull,
SELF:aDocuments, aCCs}
DO WHILE TRUE
IF oEmail:SendMail()
lOk:=TRUE
EXIT
ELSE
IF TextBox{SELF,'Problem','Problems with email - Cancel ?',
BUTTONYESNO + BOXICONQUESTIONMARK}:Show() == BOXREPLYYES
EXIT
ENDIF
ENDIF
ENDDO

oEmail:Destroy()
CollectForced()

// mail shot
ELSE

now send it

METHOD SendMail(lSkipErrors) CLASS EmailSend
LOCAL lOk:=FALSE
LOCAL cEmailType AS STRING

Default(@lSkipErrors,
FALSE)

cEmailType:=Upper(SysObject():GetSet(EmailType))

DO CASE
// errors
CASE Upper(cEmailType) == 'NONE'
SELF:cErrorMsg:='Email Parameter set to "None"'

CASE Empty(cEmailType)
SELF:cErrorMsg:='Email Parameters NOT set'

CASE Empty(LookupName(SELF:cSenderRef, #EMAIL))
SELF:cErrorMsg:='Users Email Address NOT entered'

CASE ALen(SELF:aRecipients) == 0
SELF:cErrorMsg:='No Recipients Specified'

// despatchers
CASE Upper(cEmailType) == 'SMTP'
SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
SMTP Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
IF SysObject():GetSet(SMTPRqAuth)
lOk:=SELF:SendMailSMTP( TRUE )
ELSE
lOk:=SELF:SendMailSMTP( FALSE)
ENDIF

CASE Upper(cEmailType) == 'MAPI'
SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
MAPI Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
lOk:=SELF:SendMailMapi( )

CASE Upper(cEmailType) == 'OUTLOOK'
SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
OutLook Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
lOk:=SELF:SendMailOutLook( )

CASE Upper(cEmailType) == 'GWSEND'
SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
GroupWise Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
lOk:=SELF:SendMailGW( )

CASE Upper(cEmailType) == 'LOTUS'
SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
Lotus Notes Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
lOk:=SELF:SendMailLotusNotes( )

ENDCASE

IF ! lOk .AND. ! lSkipErrors
TextBox{SysObject(), 'Email Error', 'Reply Code: ' + SELF:cReplyCode
+ CRLF + 'Error: '+ SELF:cErrorNo + CRLF + 'Message: ' +
SELF:cErrorMsg + CRLF + 'Time: ' + Time()}:Show()
ENDIF

RETURN lOk

and here's the smptp sender ... uses geoff's libs

METHOD SendMailSMTP(lAuth) CLASS EmailSend
LOCAL lOk:=FALSE
LOCAL oEmail AS CEmail
LOCAL oSmtp AS cSMTP
LOCAL n AS DWORD

oEmail := CEmail{} // empty email created
oEmail:Subject := SELF:cTitle
oEmail:cText := SELF:cMessage
oEmail:cDestList:= SELF:GetRecipList()
oEmail:cCCList := SELF:GetCCList()
oEmail:cBCCList := ""

oEmail:FromAddress := AllTrim(LookupName(SELF:cSenderRef, #EMAIL))
oEmail:FromName := AllTrim(LookupNameC(SELF:cSenderRef)) + ' of ' +
AllTrim(LookupNameX(SELF:cSenderRef))
oEmail:ReplyTo := AllTrim(LookupName(SELF:cSenderRef, #EMAIL))
oEmail:Cargo := "X-Mailer: TDOC SMTP Mailer"
IF ALen(SELF:aDocuments) > 0
FOR n:=1 TO ALen(SELF:aDocuments)
oEmail:EncodeAttachment(SELF:aDocuments[n])
NEXT
ENDIF
oEmail:EncodeEmail() // encode up the new "raw" part

oSmtp:=CSmtp{oEMail, SysObject():GetSet(SMTPSvr)}
oSmtp:SecureSMTP := lAuth
IF oSmtp:SecureSMTP
oSmtp:UserName := SysObject():GetSet(SMTPUserName)
oSmtp:PassWord := SysObject():GetSet(SMTPPassword)
ENDIF
lOk:= oSmtp:SendMail()
IF ! lOk
SELF:cReplyCode:=NTrim(oSmtp:ReplyCode)
SELF:cErrorNo:=NTrim(oSmtp:Error)
SELF:cErrorMsg:=oSmtp:ErrorMsg
ENDIF

// try and cleanup big strings
oEmail:cRaw := ""
CollectForced()

RETURN lOk


richard


From: Geoff Chambers on
On Oct 24, 7:06 am, "richard.townsendrose"
<richard.townsendr...(a)googlemail.com> wrote:
> Geoff
>
> ITS EASY
>
> just see the sample vo classes, or download something from geoff's
> site
>
> what despatcher do you need ?
> smtp, groupwise, lotusnotes, or even the dreaded outlook ...
> look at marti's mapi classes ... it'll drive almost anything.
>
> steps
> a) get the data and package it up
> b) send it and report send status.
>
>         IF SELF:oDCccEmail:Checked
>                 cMainRecip:=SELF:aNM:FIELDGET(#NAMEREF)
>                 SELF:aNM:GoTop()
>                 DO WHILE ! SELF:aNM:EoF
>                         IF ! SELF:aNM:FIELDGET(#NAMEREF) == cMainRecip
>                                 AAdd(aCCS, SELF:aNM:FIELDGET(#NAMEREF))
>                         ENDIF
>                         SELF:aNM:Skip()
>                 ENDDO
>                 SELF:aNm:Seek(cMainRecip)
>         cFull:='To: ' + AllTrim(LookupNameC(cMainRecip)) + ' of ' +
> AllTrim(LookupNameX(cMainRecip)) + CRLF + CRLF + cMsg
>                 oEMail:=EmailSend{{cMainRecip}, AsNameRef, cTitle, cFull,
> SELF:aDocuments, aCCs}
>                 DO WHILE TRUE
>                         IF oEmail:SendMail()
>                                 lOk:=TRUE
>                                 EXIT
>                         ELSE
>                                 IF TextBox{SELF,'Problem','Problems with email - Cancel ?',
> BUTTONYESNO + BOXICONQUESTIONMARK}:Show() == BOXREPLYYES
>                                         EXIT
>                                 ENDIF
>                         ENDIF
>                 ENDDO
>
>                 oEmail:Destroy()
>                 CollectForced()
>
>         // mail shot
>         ELSE
>
> now send it
>
> METHOD SendMail(lSkipErrors) CLASS EmailSend
>         LOCAL lOk:=FALSE
>         LOCAL cEmailType AS STRING
>
>         Default(@lSkipErrors,
> FALSE)
>
>         cEmailType:=Upper(SysObject():GetSet(EmailType))
>
>         DO CASE
>                 // errors
>                 CASE Upper(cEmailType) == 'NONE'
>                         SELF:cErrorMsg:='Email Parameter set to "None"'
>
>                 CASE Empty(cEmailType)
>                         SELF:cErrorMsg:='Email Parameters NOT set'
>
>                 CASE Empty(LookupName(SELF:cSenderRef, #EMAIL))
>                         SELF:cErrorMsg:='Users Email Address NOT entered'
>
>                 CASE ALen(SELF:aRecipients) == 0
>                         SELF:cErrorMsg:='No Recipients Specified'
>
>                 // despatchers
>                 CASE Upper(cEmailType) == 'SMTP'
>                         SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
> SMTP Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
>                         IF SysObject():GetSet(SMTPRqAuth)
>                                 lOk:=SELF:SendMailSMTP( TRUE )
>                         ELSE
>                                 lOk:=SELF:SendMailSMTP( FALSE)
>                         ENDIF
>
>                 CASE Upper(cEmailType)  == 'MAPI'
>                         SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
> MAPI Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
>                         lOk:=SELF:SendMailMapi( )
>
>                 CASE Upper(cEmailType) == 'OUTLOOK'
>                         SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
> OutLook Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
>                         lOk:=SELF:SendMailOutLook( )
>
>                 CASE Upper(cEmailType) == 'GWSEND'
>                         SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
> GroupWise Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
>                         lOk:=SELF:SendMailGW( )
>
>                 CASE Upper(cEmailType) == 'LOTUS'
>                         SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
> Lotus Notes Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
>                         lOk:=SELF:SendMailLotusNotes( )
>
>         ENDCASE
>
>         IF ! lOk .AND. ! lSkipErrors
>                 TextBox{SysObject(), 'Email Error', 'Reply Code: ' + SELF:cReplyCode
> + CRLF + 'Error: '+ SELF:cErrorNo + CRLF + 'Message: ' +
> SELF:cErrorMsg + CRLF + 'Time: ' + Time()}:Show()
>         ENDIF
>
> RETURN lOk
>
> and here's the smptp sender ... uses geoff's libs
>
> METHOD SendMailSMTP(lAuth) CLASS EmailSend
>         LOCAL lOk:=FALSE
>         LOCAL oEmail AS CEmail
>         LOCAL oSmtp AS cSMTP
>         LOCAL n AS DWORD
>
>         oEmail := CEmail{}                    // empty email created
>         oEmail:Subject  := SELF:cTitle
>         oEmail:cText    := SELF:cMessage
>         oEmail:cDestList:= SELF:GetRecipList()
>         oEmail:cCCList  := SELF:GetCCList()
>         oEmail:cBCCList := ""
>
>         oEmail:FromAddress := AllTrim(LookupName(SELF:cSenderRef, #EMAIL))
>         oEmail:FromName := AllTrim(LookupNameC(SELF:cSenderRef)) + ' of ' +
> AllTrim(LookupNameX(SELF:cSenderRef))
>         oEmail:ReplyTo := AllTrim(LookupName(SELF:cSenderRef, #EMAIL))
>         oEmail:Cargo := "X-Mailer: TDOC SMTP Mailer"
>         IF ALen(SELF:aDocuments) > 0
>             FOR n:=1 TO ALen(SELF:aDocuments)
>                         oEmail:EncodeAttachment(SELF:aDocuments[n])
>                 NEXT
>         ENDIF
>         oEmail:EncodeEmail()            // encode up the new "raw" part
>
>         oSmtp:=CSmtp{oEMail, SysObject():GetSet(SMTPSvr)}
>         oSmtp:SecureSMTP := lAuth
>         IF oSmtp:SecureSMTP
>                 oSmtp:UserName := SysObject():GetSet(SMTPUserName)
>                 oSmtp:PassWord := SysObject():GetSet(SMTPPassword)
>         ENDIF
>         lOk:= oSmtp:SendMail()
>         IF ! lOk
>                 SELF:cReplyCode:=NTrim(oSmtp:ReplyCode)
>                 SELF:cErrorNo:=NTrim(oSmtp:Error)
>                 SELF:cErrorMsg:=oSmtp:ErrorMsg
>         ENDIF
>
>         // try and cleanup big strings
>         oEmail:cRaw := ""
>         CollectForced()
>
> RETURN lOk
>
> richard

I have Geoff's Lib, I was just looking for some simple code to get
started.
From: Jamal on
Get yourself some third part library. Check out www.afterlogic.com

Jamal

"Geoff Chambers" <gchambers02(a)msn.com> wrote in message
news:b1cab268-b4e1-4ec4-a5c5-1650922b5812(a)p9g2000vbl.googlegroups.com...
On Oct 24, 7:06 am, "richard.townsendrose"
<richard.townsendr...(a)googlemail.com> wrote:
> Geoff
>
> ITS EASY
>
> just see the sample vo classes, or download something from geoff's
> site
>
> what despatcher do you need ?
> smtp, groupwise, lotusnotes, or even the dreaded outlook ...
> look at marti's mapi classes ... it'll drive almost anything.
>
> steps
> a) get the data and package it up
> b) send it and report send status.
>
> IF SELF:oDCccEmail:Checked
> cMainRecip:=SELF:aNM:FIELDGET(#NAMEREF)
> SELF:aNM:GoTop()
> DO WHILE ! SELF:aNM:EoF
> IF ! SELF:aNM:FIELDGET(#NAMEREF) == cMainRecip
> AAdd(aCCS, SELF:aNM:FIELDGET(#NAMEREF))
> ENDIF
> SELF:aNM:Skip()
> ENDDO
> SELF:aNm:Seek(cMainRecip)
> cFull:='To: ' + AllTrim(LookupNameC(cMainRecip)) + ' of ' +
> AllTrim(LookupNameX(cMainRecip)) + CRLF + CRLF + cMsg
> oEMail:=EmailSend{{cMainRecip}, AsNameRef, cTitle, cFull,
> SELF:aDocuments, aCCs}
> DO WHILE TRUE
> IF oEmail:SendMail()
> lOk:=TRUE
> EXIT
> ELSE
> IF TextBox{SELF,'Problem','Problems with email - Cancel ?',
> BUTTONYESNO + BOXICONQUESTIONMARK}:Show() == BOXREPLYYES
> EXIT
> ENDIF
> ENDIF
> ENDDO
>
> oEmail:Destroy()
> CollectForced()
>
> // mail shot
> ELSE
>
> now send it
>
> METHOD SendMail(lSkipErrors) CLASS EmailSend
> LOCAL lOk:=FALSE
> LOCAL cEmailType AS STRING
>
> Default(@lSkipErrors,
> FALSE)
>
> cEmailType:=Upper(SysObject():GetSet(EmailType))
>
> DO CASE
> // errors
> CASE Upper(cEmailType) == 'NONE'
> SELF:cErrorMsg:='Email Parameter set to "None"'
>
> CASE Empty(cEmailType)
> SELF:cErrorMsg:='Email Parameters NOT set'
>
> CASE Empty(LookupName(SELF:cSenderRef, #EMAIL))
> SELF:cErrorMsg:='Users Email Address NOT entered'
>
> CASE ALen(SELF:aRecipients) == 0
> SELF:cErrorMsg:='No Recipients Specified'
>
> // despatchers
> CASE Upper(cEmailType) == 'SMTP'
> SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
> SMTP Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
> IF SysObject():GetSet(SMTPRqAuth)
> lOk:=SELF:SendMailSMTP( TRUE )
> ELSE
> lOk:=SELF:SendMailSMTP( FALSE)
> ENDIF
>
> CASE Upper(cEmailType) == 'MAPI'
> SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
> MAPI Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
> lOk:=SELF:SendMailMapi( )
>
> CASE Upper(cEmailType) == 'OUTLOOK'
> SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
> OutLook Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
> lOk:=SELF:SendMailOutLook( )
>
> CASE Upper(cEmailType) == 'GWSEND'
> SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
> GroupWise Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
> lOk:=SELF:SendMailGW( )
>
> CASE Upper(cEmailType) == 'LOTUS'
> SELF:cMessage:=SELF:cMessage + CRLF + CRLF + 'Generated by the TDOC
> Lotus Notes Mail Sender at ' + Time() + ' on ' + DToC(Today()) + CRLF
> lOk:=SELF:SendMailLotusNotes( )
>
> ENDCASE
>
> IF ! lOk .AND. ! lSkipErrors
> TextBox{SysObject(), 'Email Error', 'Reply Code: ' + SELF:cReplyCode
> + CRLF + 'Error: '+ SELF:cErrorNo + CRLF + 'Message: ' +
> SELF:cErrorMsg + CRLF + 'Time: ' + Time()}:Show()
> ENDIF
>
> RETURN lOk
>
> and here's the smptp sender ... uses geoff's libs
>
> METHOD SendMailSMTP(lAuth) CLASS EmailSend
> LOCAL lOk:=FALSE
> LOCAL oEmail AS CEmail
> LOCAL oSmtp AS cSMTP
> LOCAL n AS DWORD
>
> oEmail := CEmail{} // empty email created
> oEmail:Subject := SELF:cTitle
> oEmail:cText := SELF:cMessage
> oEmail:cDestList:= SELF:GetRecipList()
> oEmail:cCCList := SELF:GetCCList()
> oEmail:cBCCList := ""
>
> oEmail:FromAddress := AllTrim(LookupName(SELF:cSenderRef, #EMAIL))
> oEmail:FromName := AllTrim(LookupNameC(SELF:cSenderRef)) + ' of ' +
> AllTrim(LookupNameX(SELF:cSenderRef))
> oEmail:ReplyTo := AllTrim(LookupName(SELF:cSenderRef, #EMAIL))
> oEmail:Cargo := "X-Mailer: TDOC SMTP Mailer"
> IF ALen(SELF:aDocuments) > 0
> FOR n:=1 TO ALen(SELF:aDocuments)
> oEmail:EncodeAttachment(SELF:aDocuments[n])
> NEXT
> ENDIF
> oEmail:EncodeEmail() // encode up the new "raw" part
>
> oSmtp:=CSmtp{oEMail, SysObject():GetSet(SMTPSvr)}
> oSmtp:SecureSMTP := lAuth
> IF oSmtp:SecureSMTP
> oSmtp:UserName := SysObject():GetSet(SMTPUserName)
> oSmtp:PassWord := SysObject():GetSet(SMTPPassword)
> ENDIF
> lOk:= oSmtp:SendMail()
> IF ! lOk
> SELF:cReplyCode:=NTrim(oSmtp:ReplyCode)
> SELF:cErrorNo:=NTrim(oSmtp:Error)
> SELF:cErrorMsg:=oSmtp:ErrorMsg
> ENDIF
>
> // try and cleanup big strings
> oEmail:cRaw := ""
> CollectForced()
>
> RETURN lOk
>
> richard

I have Geoff's Lib, I was just looking for some simple code to get
started.

From: Sherlock on
Not sure who wrote this , but give it a try

Phil McGuinness

FUNC Start
LOCAL oMail AS MyCEmail
LOCAL oSmtp AS cSmtp
LOCAL cHtml, cFstName AS STRING
LOCAL lRet AS LOGIC


oMail := MyCEmail{"Subject TEST", "ema...(a)denis.ch;ema...(a)denis.ch",
WorkDir() + "AttachFile.zip"}


//cHtml := MemoRead(cHtmlTemplate)
cFstName := 'Denis'
cHtml := ;
[<html><head><title>Welcome message</title>]+;
[<meta http-equiv="Content-Type" content="text/html;
charset=iso-8559-1">]+;
[</head>]+;
[<body bottommargin=10 topmargin=10 background="cid:background.gif">]
+;
[<table width="100%" height="10%" border=0 cellspacing=0
cellpadding=0
cols=1 rows=3>]+;
[<tr><td valign=top height="1%">]+;
[<table ALIGN=center width="100%" border=0 cellspacing=0
cellpadding=0
cols=5>]+;
[<tr><td valign=bottom width="1%"><IMG height=37 alt="Image1"
src="cid:image1.gif" width=162></td>]+;
[<td>&nbsp;</td>]+;
[<td ALIGN=middle valign=bottom nowrap><font face=Verdana
size=5><b><FONT
color=#0000ff>TITLE</FONT> &nbsp; </b></font></td>]+;
[<td>&nbsp;</td>]+;
[<td rowspan=2 valign=top width="1%"><IMG height=55 alt="image2"
src="cid:image2.gif" width=255 valign="top"></td>]+;
[</tr><tr><td colspan=3><hr color="navy"
size=1></td><td>&nbsp;</td></tr></table>Dear ]+cFstName+[,</td></tr></
table>]+;
[<font face=Arial size=2>]+;
[<p> &nbsp;</p>]+;
[</font></body></html>]


oMail:cHTML := cHtml


oMail:EncodeEmail()
#IFDEF __DEBUG
MemoWrit(WorkDir()+'Email Raw Text.txt', oMail:cRaw)
#ENDIF


oSmtp := cSmtp{oMail, 'smtp.denis.ch'}
lRet := oSmtp:SendMail()
---------------------------------------------------------------------------­---
CLASS myCEmail INHERIT CEmail
// Enhanced version that handles 3 embedded image files
// Denis Lucas, 2004
EXPORT cSubPath AS STRING
---------------------------------------------------------------------------­---
METHOD EncodeBody() CLASS myCEmail


LOCAL lFiles, lAlternate, lCID AS LOGIC
LOCAL nFiles, nN AS DWORD
LOCAL cBuffer, cTempFile, cWorkDir, cContentType, cFile, cCharSet AS
STRING
LOCAL hIn, hOut AS PTR
LOCAL nTotalBytes AS INT


// now we determine what the primary type of email is
nFiles := ALen(SELF:aAttachments)
lFiles := (nFiles > 0)
lAlternate := (SLen(SELF:cHTML) > 0)
// lazy way to search whether the HTML message contains any embedded
image
files
lCID := Instr("cid:", SELF:cHTML)


SELF:Boundary := "===DL_BOUNDARY==="
SELF:SubBoundary := "=DL_SUB_BOUNDARY="
cCharSet := '"us-ascii"'


cBuffer := 'Mime-Version: 1.0' + CRLF
cBuffer += 'X-Mailer: ' + __APPLICATION__ + CRLF
cBuffer += 'X-Info: some information' + CRLF
cBuffer += 'X-Author: Denis Lucas' + CRLF
cBuffer += 'Content-type: '


DO CASE


CASE lCID .and. !lFiles
cBuffer += 'Multipart/Related; boundary="' + SELF:Boundary + '";
type="multipart/alternative"' + CRLF
cBuffer += CRLF + "This is a multi-part message in MIME format." +
CRLF +
CRLF
// Add the text and HTML in their own part
cBuffer += ATTACH_BEGIN + SELF:Boundary + CRLF
cBuffer += 'Content-Type: multipart/alternative;' + CRLF
cBuffer += ' boundary="' + SELF:SubBoundary + '"' + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + CRLF
cBuffer += 'Content-Type: text/plain;' + CRLF
cBuffer += ' charset=' + cCharSet + CRLF
cBuffer += 'Content-Transfer-Encoding: 7bit' + CRLF + CRLF
cBuffer += SELF:cText + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + CRLF
cBuffer += 'Content-Type: text/html;' + CRLF
cBuffer += ' charset=' + cCharSet + CRLF
cBuffer += 'Content-Transfer-Encoding: 7bit' + CRLF + CRLF
cBuffer += SELF:cHTML + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + ATTACH_BEGIN + CRLF //
end
of mixed alternate parts
// attach the CIDs in subsequent parts
cTempFile := GetTempFilePath() + 'MailOut.txt'
cWorkDir := WorkDir() + SELF:cSubPath
nFiles := ALen(SELF:aContentID)
FOR nN := 1 UPTO nFiles
cFile := SELF:aContentID[nN]
cContentType := GetMimeType(cFile)
IF SLen(cContentType) = 0
cContentType := "application/octet-stream"
ENDIF


cBuffer += ATTACH_BEGIN + SELF:Boundary + CRLF
cBuffer += 'Content-Type: ' + cContentType + ';' + CRLF
cBuffer += ' name="' + cFile + '"' + CRLF
cBuffer += 'Content-transfer-encoding: base64' + CRLF
cBuffer += 'Content-ID: <' + cFile + '>' + CRLF


hOut := FCreate(cTempFile)
IF hOut != F_ERROR
hIn := FOpen(cWorkDir + cFile, FO_READ)
IF hIn != F_ERROR
nTotalBytes := EncodeBase64(hIn, hOut)

//cError := ""
//Attachment := Base64EncodeFileEx(cFileName, @cError)
//
//TextBox{,"Encode", "Bytes Encoded: " + AsString(nTotalBytes)}:Show
()
FClose(hIn)
ENDIF
FClose(hOut)
ENDIF


cBuffer += CRLF + MemoRead(cTempFile) + CRLF
FErase(cTempFile)


NEXT
cBuffer += ATTACH_BEGIN + SELF:Boundary + ATTACH_BEGIN + CRLF // end
of
mixed parts


CASE lFiles .and. lAlternate .and. !lCID
cBuffer += 'multipart/mixed;' + CRLF
cBuffer += ' boundary="' + SELF:Boundary + '"' + CRLF
cBuffer += CRLF + "This is a multi-part message in MIME format." +
CRLF +
CRLF
// Add the text and HTML in their own part
cBuffer += ATTACH_BEGIN + SELF:Boundary + CRLF
cBuffer += 'Content-Type: multipart/alternative;' + CRLF
cBuffer += ' boundary="' + SELF:SubBoundary + '"' + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + CRLF
cBuffer += 'Content-Type: text/plain;' + CRLF
cBuffer += ' charset="us-ascii"' + CRLF
cBuffer += 'Content-Transfer-Encoding: 7bit' + CRLF + CRLF
cBuffer += SELF:cText + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + CRLF
cBuffer += 'Content-Type: text/html;' + CRLF
cBuffer += ' charset="us-ascii"' + CRLF
cBuffer += 'Content-Transfer-Encoding: 7bit' + CRLF + CRLF
cBuffer += SELF:cHTML + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + ATTACH_BEGIN + CRLF //
end
OF mixed alternate parts
// attach the attachments in subsequent parts
FOR nN := 1 UPTO nFiles
cBuffer += ATTACH_BEGIN + SELF:Boundary + CRLF
cBuffer += SELF:aAttachHeaders[nN]+ CRLF + CRLF
cBuffer += SELF:aAttachments[nN]
cBuffer += CRLF
NEXT
cBuffer += ATTACH_BEGIN + SELF:Boundary + ATTACH_BEGIN + CRLF // end
of
mixed parts


// HTML, CIDs and attachments
CASE lFiles .and. lAlternate .and. lCID
cBuffer += 'multipart/mixed;' + CRLF
cBuffer += ' boundary="' + SELF:Boundary + '"' + CRLF
cBuffer += CRLF + "This is a multi-part message in MIME format." +
CRLF +
CRLF
// Add the text and HTML in their own part
cBuffer += ATTACH_BEGIN + SELF:Boundary + CRLF
cBuffer += 'Content-Type: multipart/alternative;' + CRLF
cBuffer += ' boundary="' + SELF:SubBoundary + '"' + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + CRLF
cBuffer += 'Content-Type: text/plain;' + CRLF
cBuffer += ' charset="us-ascii"' + CRLF
cBuffer += 'Content-Transfer-Encoding: 7bit' + CRLF + CRLF
cBuffer += SELF:cText + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + CRLF
cBuffer += 'Content-Type: text/html;' + CRLF
cBuffer += ' charset="us-ascii"' + CRLF
cBuffer += 'Content-Transfer-Encoding: 7bit' + CRLF + CRLF
cBuffer += SELF:cHTML + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + ATTACH_BEGIN + CRLF //
end
OF mixed alternate parts


// attach the attachments in subsequent parts
FOR nN := 1 UPTO nFiles
cBuffer += ATTACH_BEGIN + SELF:Boundary + CRLF
cBuffer += SELF:aAttachHeaders[nN]+ CRLF + CRLF
cBuffer += SELF:aAttachments[nN]
cBuffer += CRLF
NEXT


// attach the CIDs in subsequent parts
cTempFile := GetTempFilePath() + 'MailOut.txt'
cWorkDir := WorkDir() + SELF:cSubPath
nFiles := ALen(SELF:aContentID)
FOR nN := 1 UPTO nFiles
cFile := SELF:aContentID[nN]
cContentType := GetMimeType(cFile)
IF SLen(cContentType) = 0
cContentType := "application/octet-stream"
ENDIF


cBuffer += ATTACH_BEGIN + SELF:Boundary + CRLF
cBuffer += 'Content-Type: ' + cContentType + ';' + CRLF
cBuffer += ' name="' + cFile + '"' + CRLF
cBuffer += 'Content-transfer-encoding: base64' + CRLF
cBuffer += 'Content-ID: <' + cFile + '>' + CRLF


hOut := FCreate(cTempFile)
IF hOut != F_ERROR
hIn := FOpen(cWorkDir + cFile, FO_READ)
IF hIn != F_ERROR
nTotalBytes := EncodeBase64(hIn, hOut)
FClose(hIn)
ENDIF
FClose(hOut)
ENDIF


cBuffer += CRLF + MemoRead(cTempFile) + CRLF
FErase(cTempFile)
NEXT


cBuffer += ATTACH_BEGIN + SELF:Boundary + ATTACH_BEGIN + CRLF // end
of
mixed parts


CASE lFiles
// attachments but text only message
cBuffer += 'multipart/mixed;' + CRLF
cBuffer += ' boundary="' + SELF:Boundary + '"' + CRLF
cBuffer += CRLF + "This is a multi-part message in MIME format." +
CRLF +
CRLF
cBuffer += ATTACH_BEGIN + SELF:Boundary + CRLF
cBuffer += 'Content-Type: text/plain;' + CRLF
cBuffer += ' charset="us-ascii"' + CRLF
cBuffer += 'Content-Transfer-Encoding: 7bit' + CRLF + CRLF
cBuffer += SELF:cText + CRLF + CRLF
// attach the attachments
FOR nN := 1 UPTO nFiles
cBuffer += ATTACH_BEGIN + SELF:Boundary + CRLF
cBuffer += SELF:aAttachHeaders[nN]+ CRLF + CRLF
cBuffer += SELF:aAttachments[nN]
cBuffer += CRLF
NEXT
cBuffer += ATTACH_BEGIN + SELF:Boundary + ATTACH_BEGIN + CRLF // end
of
mixed parts


CASE lAlternate
// no attachments but HTML and text
cBuffer += 'multipart/alternative;' + CRLF
cBuffer += ' boundary="' + SELF:SubBoundary + '"' + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + CRLF
cBuffer += 'Content-Type: text/plain;' + CRLF
cBuffer += ' charset="us-ascii"' + CRLF
cBuffer += 'Content-Transfer-Encoding: 7bit' + CRLF + CRLF
cBuffer += SELF:cText + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + CRLF
cBuffer += 'Content-Type: text/html;' + CRLF
cBuffer += ' charset="us-ascii"' + CRLF
cBuffer += 'Content-Transfer-Encoding: 7bit' + CRLF + CRLF
cBuffer += SELF:cHTML + CRLF + CRLF
cBuffer += ATTACH_BEGIN + SELF:SubBoundary + ATTACH_BEGIN + CRLF //
end
OF mixed alternate parts


OTHERWISE
// text only and no attachments
cBuffer += 'text/plain;' + CRLF
cBuffer += ' charset="us-ascii"' + CRLF
cBuffer += 'Content-Transfer-Encoding: 7bit' + CRLF + CRLF
cBuffer += SELF:cText+CRLF
ENDCASE


cBuffer += CRLF


RETURN cBuffer
---------------------------------------------------------------------------­---
METH Init(cSubject, cDestList, cAttach) CLASS myCEmail
SUPER:Init()


SELF:cDestList := StrTran(cDestList, ',', ';')
SELF:FromName := __APPLICATION__
SELF:FromAddress := "d...(a)denis.ch"
SELF:cSubPath := ""
SELF:cText := "My plain text"
SELF:cSubject := cSubject


// WARNING: call EncodeAttachement() before you assign
self:aContentID
IF !IsNil(cAttach)
SELF:EncodeAttachment(cAttach)
ENDIF
SELF:aContentID := {"background.gif","image1.gif","image2.gif"}