logo
Powered by QM on a Rpi server
Home
About OpenQM
Sales and Downloads
Help and Support
About
  Privacy Policy
  Contact Us
  Partners
  Services
  Applications
Login

KnowledgeBase 00003: Sending Emails (Windows)

Last updated: 22 Jul 2016
Applies to: All versions
Search  
Top level index       Full Index Search Tips
Previous article     Next article

Overview

Emails can be sent from QM applications using standard operating system components with no additional software.

This article discusses how to send emails on Windows systems.


Using Windows IIS

Ideally, configure Windows IIS on the server. Alternatively, this method will work if the IIS file structures are accessed across a local network.

All that is necessary to send an email is to prepare a text file with the standard email headers, writing this data into the pickup subdirectory of the IIS mailroot area. Note that use of the SAFEDIR configuration parameter to perform a two stage update to directory files can result in IIS sending the email twice.

The program below is similar to the one used by the OpenQM web site to send emails. This example shows inclusion of PDF attachments. Other attachment file types can be handled in a similar manner.

subroutine smtp.mail((recipient), subject, text, (attachments), sender, eml.id) 
$catalogue global 
* recipient   = target email address. May be multivalued. 
* subject     = subject line. 
* text        = message text. Field marks become newlines. 
* attachments = pathnames of attachment files. 
* sender      = sender's email address. 
   mtext = 'From: <' : sender : '>' 
   mtext<-1> = 'To: <' : change(recipient, @vm, '>,<') : '>' 
   mtext<-1> = 'Subject: ' : subject 
   mtext<-1> = 'Date: ' : oconv(date(), 'D4WADMYL[A3", ",Z,A3]') : ' ' : oconv(time(), 'MTS') 
   if attachments = '' then 
      mtext<-1> = '' 
      mtext<-1> = text 
   end else 
      mtext<-1> = 'MIME-Version: 1.0' 
      mtext<-1> = 'Content-Type: multipart/mixed;' 
      mtext<-1> = '   boundary="----=_NextPart"' 
      mtext<-1> = '' 
      mtext<-1> = 'This is a multi-part message in MIME format.' 
      mtext<-1> = '' 
      mtext<-1> = '------=_NextPart' 
      mtext<-1> = 'Content-Type: text/plain;' 
      mtext<-1> = '   charset="iso-8859-2"' 
      mtext<-1> = 'Content-Transfer-Encoding: quoted-printable' 
      mtext<-1> = '' 
      mtext<-1> = text 
      setrem 0 on attachments 
      loop 
         pathname = remove(attachments, more) 
         dirname = field(pathname, '\', 1, dcount(pathname, '\') - 1) 
         filename = field(pathname, '\', dcount(pathname, '\')) 
         type = downcase(field(filename, '.', dcount(filename, '.'))) 
         openpath dirname to att.f then 
            mark.mapping att.f, off 
            read att from att.f, filename then 
               att = fold(oconv(att, 'B64'), 72) 
            end else 
               logmsg 'Error ' : status() : '.' : os.error() : ' reading email attachment directory ' : pathname 
            end 
            close att.f 
         end else 
            logmsg 'Error ' : status() : '.' : os.error() : ' opening email attachment directory ' : dirname 
         end 
         begin case 
            case type = 'pdf' 
               mtext<-1> = '' 
               mtext<-1> = '------=_NextPart' 
               mtext<-1> = 'Content-Type: application/pdf;' 
               mtext<-1> = '   name="' : filename : '"' 
               mtext<-1> = 'Content-Transfer-Encoding: base64' 
               mtext<-1> = 'Content-Disposition: attachment;' 
               mtext<-1> = '   filename="' : filename : '"' 
               mtext<-1> = '' 
               mtext<-1> = att 
            case 1 
               logmsg 'Unrecognised email attachment type in ' : pathname 
         end case 
      while more 
      repeat 
      mtext<-1> = '' 
      mtext<-1> = '------=_NextPart--' 
   end 
   openpath 'c:\inetpub\mailroot\pickup' to pku.f then 
      write mtext to pku.f, eml.id 
      close pku.f 
   end else 
      logmsg 'Error ' : status() : '.' : os.error() : 'opening email pickup directory' 
   end 
   return 
end 

Related Articles

None.



Please tell us if this article was helpful
Very     Slightly     Not at all
Comments
Email (optional)