# Friday, July 15, 2005

The following code works with w3Jmail, which is available as FREEWARE.  They have other licenses available as well, so should you need more functionality than the code below provides you can have it.  Their documentation is good, especially when compared to most other 3rd party components for email.  I've used w3JMail with excellent success and highly recommend it (I'm not affiliated with the company in anyway). 

*******************************
*!* Example of using SendViaJMail
*******************************
***Requires FREE w3JMail v4.4 (code works with v3.0 and above)
***Download at
http://tech.dimac.net/default2.asp?M=Products/MenuCOM.asp&P=Products/w3JMail/start.htm
*******************************
#DEFINE PRIORITYURGENT 1
#DEFINE PRIORITYHIGH 2
#DEFINE PRIORITYNORMAL 3
#DEFINE PRIORITYLOW 4
#DEFINE PRIORITYLOWEST 5

DIMENSION aryAttach(2)
aryAttach(1) = "C:\attachment1.txt" && change to an actual file that exists on your computer
aryAttach(2) = "C:\attachment2.zip" && change to an actual file that exists on your computer

LOCAL lcToAddress, lcToName, lcFromAddress, lcFromName, lcSubject, lcBody, lcCC, lcBCC, lcMailServer, lcUserName, lcPassword, lnPort, lcErrReturn
lcToAddress = "
someone@somehost.com"
lcToName =  "Their Name"
lcFromAddress = "
me@myhost.com"
lcFromName = "My Name"
lcSubject = "Hey Have You Tried VFP Email?"
lcBody = "Just wanted to let you know that VFP is pretty versatile and has a lot of ways to send email."
lcCC = "
someoneelse@someotherhost.com"
lcBCC = "
myboss@bosshost.com"
lcMailServer = "mail.myhost.com"
lcUserName = "MyUsername" && my SMTP username
lcPassword = "My_PaSsWoRd" && my SMTP password
lnPort = 25 && SMTP standard port
llHTMLFormat = .F. && Change to .T. if lcBody is HTML
SendViaJMail(@lcErrReturn, lcToAddress, lcToName, lcFromAddress, lcFromName, lcSubject, lcBody, @aryAttach, lcCC, lcBCC, lcMailServer, lcUserName, lcPassword, lnPort, PRIORITYURGENT, llHTMLFormat)

IF EMPTY(lcErrReturn)
 MESSAGEBOX("'" + lcSubject + "' sent successfullly.", 64, "Send email via JMail")
ELSE
 MESSAGEBOX("'" + lcSubject + "' failed to be sent.  Reason:" + CHR(13) + lcErrReturn, 64, "Send email via JMail")
ENDIF


*******************************************
PROCEDURE SendViaJMail(tcReturn, tcToAddress, tcToName, tcFromAddress, tcFromName, tcSubject, tcBody, taFiles, tcCC, tcBCC, tcMailServer, tcUserName, tcPassword, tnPort, tnPriority, tlHTMLFormat)
*******************************************
 LOCAL loSMTPMail, lnCountAttachments, loError AS EXCEPTION

 tcReturn = ""

 TRY
     loSMTPMail  = CREATEOBJECT("jmail.SMTPMail")
     WITH loSMTPMail
      IF TYPE("tcMailServer") = "C"
       .ServerAddress = tcMailServer
       IF TYPE("tcUserName") = "C" AND TYPE("tcPassword") = "C"
        .ServerAddress = tcUserName + ":" + tcPassword + "@" + .ServerAddress
       ENDIF
       IF TYPE("tnPort") = "N"
        .ServerAddress = .ServerAddress + ":" + TRANSFORM(tnPort)
       ENDIF
      ENDIF
*!*   .Charset = "US-ASCII" && Can change charset, iso-8859-1 is default
  IF TYPE("tcToName") = "C"
   .AddRecipientEx(tcToAddress, tcToName )
  ELSE
         .AddRecipient(tcToAddress)
       ENDIF
         IF TYPE("tcCC") = "C"
          .AddRecipientCc(tcCC)
         ENDIF
         IF TYPE("tcBCC") = "C"
          .AddRecipientBcc(tcBCC)
  ENDIF
  IF TYPE("tcFromAddress") = "C"
         .Sender = tcFromAddress
        endif
         IF TYPE("tcFromName") = "C"
          .SenderName = tcFromName
         ENDIF
         IF TYPE("tlHTMLFormat") = "L" AND tlHTMLFormat
          .ContentType = "text/html"
         ELSE
          .ContentType = "text/plain" && Default
         ENDIF
         .Subject = tcSubject
         .Body = tcBody
         IF TYPE("tnPriority") = "N"
          .Priority = tnPriority
         ELSE
          .Priority = 3 && Default
         ENDIF
         IF TYPE("taFiles",1) = "A"
             FOR lnCountAttachments = 1 TO ALEN(taFiles)
                 .AddAttachMent(taFiles(lnCountAttachments))
             ENDFOR
         ENDIF
         .Execute()
     ENDWITH
 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
     RELEASE loSMTPMail
     loSMTPMail  = .NULL.
 ENDTRY
ENDPROC

Friday, July 15, 2005 10:44:39 PM (GMT Daylight Time, UTC+01:00)  #    Comments [1]
Thursday, June 29, 2006 5:29:04 PM (GMT Daylight Time, UTC+01:00)
You know how to deal with SMTP authentication with a username necessarily to be the complete email?

Example:

gianni.t@libero.it:mypass@mail.libero.it

I cannot use simply
gianni.t:mypass@mail.libero.it

But probably the two @ knocks and the smtp server did not like the string at all.

In Outlook Express instead function without a glitch.
Giovanni Turri
All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview

 

Archive

<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910