BASIC Multipart Simple


This is a simple example of a Multipart Mime email with HTML and Text alternative using
Content-Type: text/html
Content-Type: text/plain

An example in powerbasic

FUNCTION MultiPart2Email( sSrvr      AS STRING,_  ' Send HTML + Text alternative
                                          sUser      AS STRING,_ ' (no attachments)
                                          sPass      AS STRING,_
                                          sFrom      AS STRING,_
                                          sTo        AS STRING,_
                                          sMailDate  AS STRING,_   
                                          sSubject   AS STRING,_
                                          sTextBody  AS STRING,_ 
                                          sHTMLBody  AS STRING,_ 
                                          sRet       AS STRING ) AS LONG

' Each line of characters must be no more than 1000 chars (including the CRLF)
' Single Quote is equivalent to Double Quote only in sHTMLBody
                 
  LOCAL sBody, sBnd AS STRING
   
    sBnd = "----=_Part_143151_18856144"

    IF LEN(sMailDate) THEN sBody = "Date: " + sMailDate             + $CRLF

    sBody = sBody + "From: yourdomain Auto-Mailer"                    + $CRLF
    sBody = sBody + "reply-to: help@fyourdomain.com"                 + $CRLF
    sBody = sBody + "To: "      + sTo                                            + $CRLF 
    sBody = sBody + "Subject: " + sSubject                                  + $CRLF 
    sBody = sBody + "MIME-Version: 1.0"                                    + $CRLF


    sBody = sBody + "Content-TYPE: multipart/alternative; boundary="+ $DQ+sBnd+$DQ + $CRLF
    sBody = sBody + ""                                                                          + $CRLF  ' VIP seperator 

    sBody = sBody + "--" + sBnd                                                            + $CRLF
    sBody = sBody + "Content-TYPE: text/plain; charset=ISO-8859-1"      + $CRLF
    sBody = sBody + "Content-Transfer-Encoding: 7bit"                           + $CRLF    
    sBody = sBody + ""                                                                         + $CRLF  ' VIP seperator   
    sBody = sBody + sTextBody                                                           + $CRLF  'Text Message
    sBody = sBody + ""                                                                        + $CRLF  ' VIP seperator
 
    sBody = sBody + "--" + sBnd                                                           + $CRLF
    sBody = sBody + "Content-TYPE: text/html; charset=ISO-8859-1"     + $CRLF                               
    sBody = sBody + "Content-Transfer-Encoding: 7bit"                          + $CRLF   
    sBody = sBody + ""                                                                        + $CRLF  ' VIP seperator                    
    sBody = sBody + sHTMLBody                                                         + $CRLF  ' HTML part
    sBody = sBody + ""                                                                        + $CRLF  ' VIP seperator 
                

    sBody = sBody + "--" + sBnd + "--"                                                 + $CRLF
    sBody = sBody + ""                                                                       + $CRLF  ' VIP seperator 

  FUNCTION = SMTPTLS( sSrvr, sUser, sPass, sFrom, sTo, sBody, sRet )   '  Send the email 

END FUNCTION 
Comments