COBOL Email Routine

                                                    

Introduction

 

    How would you like to use COBOL to email messages and attachments directly from your COBOL program just like other windows applications ? To automate the distribution process of reports, events, messages and such ? The ACS Corporation  supplies a routine that allow COBOL programs to do this. This means your COBOL program can send emails with all the bells and whistles of regular windows email. Including TO addresses, CC (Carbon Copy) addresses, BCC (Blind Carbon Copy) addresses, Multi-Line Text and multiple attachments.

     The COBOL programmer can use the following routine for sending emails:


Send_Mail

    This function allows the program to send Email through an existing SMTP server. Attachments, Carbon Copies, Blind Carbon Copies are supported.
 

Parameters

 

  Parm 1 SMTP Server

        SMTP Server is the textual name given for outbound SMTP Email Server. This information can be determined by looking at your email account information. Typically, this will look like: mail.yourdomain.com smtp.yourdomain.com
  Parm 2 From Name

        From Name is the textual name of the person, system or application that is creating this email. However, this name can be completely bogus. For example, if you were sending out email info that would not require a reply.
  Parm 3 From Email Address

        From Email Address is the email address the person receiving this email might reply to. Typically, this will look like [email protected]. However, this address can be completely bogus. For example, if you were sending out email info that would not require a reply.
  Parm 4 To Email Address(s)

        To Email Address is the email address(s) of the persons receiving this email. Typically, this will look like [email protected] You can specify multiple "To" addresses by separating them with a semi-colon (;) character.
  Parm 5 Carbon Copy Address(s)

        Carbon Copy Address(s) are email address(s) of people who will receive this email. The person(s) in this Parm  will see who else this email is sent to, except people in  Parm 6. You can specify multiple addresses by separating them with a semi-colon (;) character.
  Parm 6 Blind Carbon Copy Address(s)

        Blind Carbon Copy Address(s) are email address(s) of people who will receive this email. The person(s) in this Parm will not see who else this email is sent to. Nor are they they seen by others (e.g. To Email Address). You can specify multiple addresses by separating them with a semi-colon (;) character.
  Parm 7 Subject

        Subject is the textual reference to this email. e.g. "Monthly Expense Data Listed Below"
  Parm 8 Body Text

        Body Text is the actual description/text/information in this email. Multiple lines are support by stringing a carriage return and linefeed at the end of each line. e.g. "line 1 text goes here", x'0d', x'0a'.
  Parm 9 File Attachment(s)

        Attachment(s) are the files (complete with paths) to be sent with this email message. You can specify multiple attachments by separating them with a semi-colon (;) character. Attachments are good for sending data files and other information that is particular to a system. Such as spreadsheets.
 

Return Values
        The return value of zero (0) means a successful tranmission to your SMTP server. It does not mean all of your email addresses are valid. The return value of one (1) means the transmission failed. Usually because of an invalid SMTP server name or missing Parm.
 
Remarks
        All of these Parms are a NULL (x'00') terminated string. Parms 1,2,3 & 7 are required. At least one Parm 4 or one Parm 6 is required. Any other parm not used must have a NULL (x'00') as the first character. Otherwise, the routine will think it has data to be processed. The size of Parms 4,5,6,8 & 9 may be changed within the copybook should the size be to small for your application. However, the size must be evenly dividable by 8. e.g. 256/8 = 32 with no remainder. The email routine requires Windows .Net Framework support. At least .Net Framework version 2.0 the following operating systems will not support .Net Framework, there may be others.
  Microsoft Windows 95
  Microsoft Windows NTŪ Server
  Windows NT Workstation
 
Code Example
  STRING 'mail.YOURSMTP.com', x'00' DELIMITED BY SIZE INTO Mail-SMTPserver.
  STRING 'From Name Here', x'00' DELIMITED BY SIZE INTO Mail-FromName.
  STRING 'From Address.com', x'00' DELIMITED BY SIZE INTO Mail-FromAddress.
  STRING 'ToMailAddress.com', x'00' DELIMITED BY SIZE INTO Mail-ToAddress.

  STRING 'BCCaddress.com;NexBCCaddress.com', x'00' DELIMITED BY SIZE INTO Mail-BCCAddress.
  STRING 'Subject Goes Here !!!', x'00' DELIMITED BY SIZE INTO Mail-Subject.
  STRING 'Let Me Know If You Get This Email !', x'0d', x'0a',  'text line 2 here', x'00' DELIMITED BY SIZE INTO Mail-Text.
  STRING 'c:\attachment1.txt;c:\attachment2.exe', x'00' DELIMITED BY SIZE INTO Mail-Attachments.
  PERFORM Send-Mail.
Send-Mail.
  Call 'S_Send_Mail' USING
      BY REFERENCE Mail-SMTPserver,
      BY REFERENCE Mail-FromName,
      BY REFERENCE Mail-FromAddress,
      BY REFERENCE Mail-ToAddress,
      BY REFERENCE Mail-CCAddress,
      BY REFERENCE Mail-BCCAddress,
      BY REFERENCE Mail-Subject,
      BY REFERENCE Mail-Text,
      BY REFERENCE Mail-Attachments
  GIVING RETURN-CODE-NUM.
 

CopyBook

    A COBOL copybook with all these parameters, documentation, comments and sample code is supplied with this package.