MTA Programmer s Reference Manual

Similar documents
Sun Control Station. Performance Module. Sun Microsystems, Inc. Part No September 2003, Revision A

SunVTS Quick Reference Card

Solaris 9 9/04 Installation Roadmap

Sun Java Enterprise System 2003Q4 Deployment Example Series: Evaluation Scenario

Sun Java System Application Server Platform Edition Q2 Update 2 Release Notes

Tuning LDAP to Improve Searches in Communications Services Clients

Cable Management Guide

Designing a Fault-Tolerant Network Using Sun Netra CP3x40 Switches

Sun Rack Cabinet Extension Installation Guide

Sun Management Center 3.6 Version 7 Add-On Software Release Notes

SunVTS Quick Reference Card

Sun Management Center 3.6 Performance Reporting Manager User s Guide

Sun Java System Connector for Microsoft Outlook Q4 Installation Guide

Sun Java System Directory Server Release Notes for HP-UX

Sun Management Center 4.0 Version 4 Add-On Software Release Notes

Sun Management Center 4.0 Version 3 Add-On Software Release Notes

Sun StorEdge Network 2 Gb Brocade SilkWorm 3200 and 3800 Switches Release Notes

Solaris 8 6/00 Sun Hardware Roadmap

Deployment Guide. Sun ONE Identity Server. Version 6.1

Identity Manager 7.0 Deployment Tools

man pages section 6: Demos

Sun Ultra TM. 5 and Ultra 10 Product Notes. Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, CA U.S.A.

Web Proxy Server Configuration File Reference

Sun Management Center 3.5 Supplement for VSP High-End Entry Servers (Workgroup Servers)

StorageTek Host Software Component (HSC) MVS Software

Java Enterprise System Telecommunications Provider Scenario

Sun Control Station. Software Installation. Sun Microsystems, Inc. Part No January 2004, Revision A

Sun Remote System Control (RSC) Release Notes

Sun StorEdge 3310 SCSI Array Best Practices Manual

Sun Fire V125 Server Getting Started Guide

Sun Fire V60x and V65x Servers ReadMe

Sun Update Manager 1.0 Administration Guide

Sun Java System Access Manager Release Notes for Microsoft Windows

Sun Fire V210 and V240 Servers Getting Started Guide

Sun Fire V100 Server Product Notes

Sun Installation Assistant for Windows and Linux User s Guide

Solaris 10 Installation Guide: Solaris Flash Archives (Creation and Installation)

Memory Hole in Large Memory X86 Based Systems

Access Manager 6 Federation Management Guide

Sun Fire X4250 Volume Configuration Guide

Sun Netra TM X4200 M2 Server Product Notes

Sun Management Center 4.0 Version 2 Add-On Software Release Notes

System Management Services (SMS) 1.6 Software Release Notes

Sun Cluster 2.2 7/00 Data Services Update: Lotus Domino 4.6.3

Font Administrator User s Guide

Sun Blade 1000 and Sun Blade 2000 Product Notes

Sun Fire V20z Server Installation Guide

Sun Remote System Control (RSC) 2.2 Release Notes

Solaris 8 User Supplement. Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, CA U.S.A.

Cluster Platform 15K/9960 System

Sun StorEdge T3 Disk Tray Cabinet Installation Guide

Font Administrator User s Guide. Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, CA U.S.A.

Sun Multipath Failover Driver 1.0 for AIX User s Guide

Sun Fire V490 Server Product Notes

Sun x64 Servers Windows Server 2003 R2 Operating System Preinstall Release Notes

Traditional Chinese Solaris Release Overview

Rackmount Placement Matrix

Sun OpenSSO Enterprise Policy Agent 3.0 Guide for IBM WebSphere Application Server 6.1/7.0 and WebSphere Portal Server 6.1

Sun Fire V60x and V65x BIOS and Firmware Update ReadMe

Web Proxy Server NSAPI Developer s Guide

Sun Patch Manager 2.0 Administration Guide for the Solaris 8 Operating System

Sun Management Center 3.5 Service Availability Manager User s Guide

UltraSPARC - IIs CPU Module Installation Guide

Sun Update Connection - Enterprise 1.0 Quick Start Guide: Getting Started

Brocade 5100 Switch Hardware Release Notes

Content Delivery Server 5.1 Content Developer Guide

Java Desktop System Release 2 Installation Guide

Sun StorageTek Backup Manager Release Notes

SUN SEEBEYOND eindex SPV ENTERPRISE DATA MANAGER USER S GUIDE. Release 5.1.2

Deployment Guide. Sun TM ONE Directory Server. Version 5.2

Sun Role Manager 4.1. Manual Installation Guide. Sun Microsystems, Inc Network Circle Santa Clara, CA U.S.A.

Sun Blade 6048 Modular System Overview

Scenario Planning - Part 1

Sun GlassFishWeb Space Server 10.0 Release Notes

Sun StorEdge Enterprise 2 Gb FC Single and Dual Port Host Bus Adapter Release Notes

Crypto Key Management Station

The Solaris Security Toolkit - Quick Start

Solaris 8 User Supplement. Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, CA U.S.A.

Java Desktop System Release 3 Troubleshooting Guide

Defining Constants and Variables. Sun Microsystems, Inc Network Circle Santa Clara, CA U.S.A.

Sun Fire X4170, X4270, and X4275 Servers Linux, VMware, Solaris, and OpenSolaris Operating Systems Installation Guide

Solaris PC NetLink 1.2 Installation Guide

Sun Enterprise System 336-Mhz Processor Upgrade Instructions

Sun Microsystems, Inc Network Circle Santa Clara, CA U.S.A. Sun Role Manager 4.1 Installation Guide

Sun Management Center 3.6 Supplement for the Sun Fire, Sun Blade, and Netra Systems

Ultra Enterprise 6000/5000/4000 Systems Power Cord Installation

Sun Management Center 3.0 Service Availability Manager User s Guide

Brocade DCX-4S Backbone Hardware Release Notes

GNOME 2.0 Desktop for the Solaris Operating Environment User Guide

Solaris 8 Desktop User Supplement. Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, CA U.S.A.

SUN SEEBEYOND eway TCP/IP HL7 ADAPTER USER S GUIDE. Release 5.1.2

Sun Blade 1500 Product Notes

Sun Blade TM T63X0 PCIe Pass- Through Fabric Expansion Module User s Guide

Sun Desktop Manager 1.0 Developer Guide

Sun Java Enterprise System Technical Note: Configuring Web Server Reverse Proxy Plugin for Communications Express

Sun Blade 2500 Workstation Product Notes

Sun Fire V480 Server Product Notes

SUN SEEBEYOND eway ADAPTER FOR LOTUS NOTES/DOMINO USER S GUIDE. Release 5.1.2

Sun Fire TM E2900 Systems Getting Started

Sun Fire X4600 Server Windows Operating System Installation Guide

Transcription:

MTA Programmer s Reference Manual Sun ONE Messaging Server Version 6.0 816-6742-10 December 2003

Copyright 2003 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this document. In particular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents or pending patent applications in the U.S. and in other countries. THIS PRODUCT CONTAINS CONFIDENTIAL INFORMATION AND TRADE SECRETS OF SUN MICROSYSTEMS, INC. USE, DISCLOSURE OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SUN MICROSYSTEMS, INC. U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. This distribution may include materials developed by third parties. Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S. and in other countries, exclusively licensed through X/Open Company, Ltd. Sun, Sun Microsystems, the Sun logo, Java, Solaris, JDK, Java Naming and Directory Interface, JavaMail, JavaHelp, J2SE, iplanet, the Duke logo, the Java Coffee Cup logo, the Solaris logo, the SunTone Certified logo and the Sun ONE logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon architecture developed by Sun Microsystems, Inc. Legato and the Legato logo are registered trademarks, and Legato NetWorker, are trademarks or registered trademarks of Legato Systems, Inc. The Netscape Communications Corp logo is a trademark or registered trademark of Netscape Communications Corporation. The OPEN LOOK and Sun(TM) Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface, which license also covers Sun s licensees who implement OPEN LOOK GUIs and otherwise comply with Sun s written license agreements. This product includes software developed by Computing Services at Carnegie Mellon University (http://www.cmu.edu/computing/. Products covered by and information contained in this service manual are controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited. DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. Copyright 2003 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, Etats-Unis. Tous droits réservés. Sun Microsystems, Inc. détient les droits de propriété intellectuels relatifs à la technologie incorporée dans le produit qui est décrit dans ce document. En particulier, et ce sans limitation, ces droits de propriété intellectuelle peuvent inclure un ou plus des brevets américains listés à l adresse http://www.sun.com/patents et un ou les brevets supplémentaires ou les applications de brevet en attente aux Etats - Unis et dans les autres pays. CE PRODUIT CONTIENT DES INFORMATIONS CONFIDENTIELLES ET DES SECRETS COMMERCIAUX DE SUN MICROSYSTEMS, INC. SON UTILISATION, SA DIVULGATION ET SA REPRODUCTION SONT INTERDITES SANS L AUTORISATION EXPRESSE, ECRITE ET PREALABLE DE SUN MICROSYSTEMS, INC. Cette distribution peut comprendre des composants développés par des tierces parties. Des parties de ce produit pourront être dérivées des systèmes Berkeley BSD licenciés par l Université de Californie. UNIX est une marque déposée aux Etats-Unis et dans d autres pays et licenciée exclusivement par X/Open Company, Ltd. Sun, Sun Microsystems, le logo Sun, Java, Solaris, JDK, Java Naming and Directory Interface, JavaMail, JavaHelp, J2SE, iplanet, le logo Duke, le logo Java Coffee Cup, le logo Solaris, le logo SunTone Certified et le logo Sun[tm] ONE sont des marques de fabrique ou des marques déposées de Sun Microsystems, Inc. aux Etats-Unis et dans d autres pays. Toutes les marques SPARC sont utilisées sous licence et sont des marques de fabrique ou des marques déposées de SPARC International, Inc. aux Etats-Unis et dans d autres pays. Les produits portant les marques SPARC sont basés sur une architecture développée par Sun Microsystems, Inc. Le logo Netscape Communications Corp est une marque de fabrique ou une marque déposée de Netscape Communications Corporation. L interface d utilisation graphique OPEN LOOK et Sun(TM) a été développée par Sun Microsystems, Inc. pour ses utilisateurs et licenciés. Sun reconnaît les efforts de pionniers de Xerox pour la recherche et le développement du concept des interfaces d utilisation visuelle ou graphique pour l industrie de l informatique. Sun détient une license non exclusive de Xerox sur l interface d utilisation graphique Xerox, cette licence couvrant également les licenciés de Sun qui mettent en place l interface d utilisation graphique OPEN LOOK et qui, en outre, se conforment aux licences écrites de Sun. Ce produit comprend du logiciel dévelopé par Computing Services à Carnegie Mellon University (http://www.cmu.edu/computing/). Les produits qui font l objet de ce manuel d entretien et les informations qu il contient sont regis par la legislation americaine en matiere de controle des exportations et peuvent etre soumis au droit d autres pays dans le domaine des exportations et importations. Les utilisations finales, ou utilisateurs finaux, pour des armes nucleaires, des missiles, des armes biologiques et chimiques ou du nucleaire maritime, directement ou indirectement, sont strictement interdites. Les exportations ou reexportations vers des pays sous embargo des Etats-Unis, ou vers des entites figurant sur les listes d exclusion d exportation americaines, y compris, mais de maniere non exclusive, la liste de personnes qui font objet d un ordre de ne pas participer, d une facon directe ou indirecte, aux exportations des produits ou des services qui sont regi par la legislation americaine en matiere de controle des exportations et la liste de ressortissants specifiquement designes, sont rigoureusement interdites. LA DOCUMENTATION EST FOURNIE "EN L ETAT" ET TOUTES AUTRES CONDITIONS, DECLARATIONS ET GARANTIES EXPRESSES OU TACITES SONT FORMELLEMENT EXCLUES, DANS LA MESURE AUTORISEE PAR LA LOI APPLICABLE, Y COMPRIS NOTAMMENT TOUTE GARANTIE IMPLICITE RELATIVE A LA QUALITE MARCHANDE, A L APTITUDE A UNE UTILISATION PARTICULIERE OU A L ABSENCE DE CONTREFACON.

Contents About This Manual............................................................ 11 Who Should Read This Manual.......................................................... 11 What You Need to Know................................................................ 12 How This Manual is Organized.......................................................... 12 Document Conventions................................................................. 13 Monospaced Font................................................................... 13 Italicized Font....................................................................... 13 Square or Straight Brackets........................................................... 13 Platform-specific Syntax.............................................................. 13 Where to Find Related Information....................................................... 13 Where to Find This Manual Online....................................................... 14 Related Third-Party Web Site References.................................................. 15 Part 1 MTA SDK............................................................ 17 Chapter 1 MTA SDK Concepts and Overview...................................... 19 Channel Programs and Message Queuing................................................. 19 Managing Multiple Threads: Contexts.................................................... 20 Enqueuing Messages................................................................... 20 Message Components................................................................ 21 Envelope........................................................................ 21 Header.......................................................................... 21 Body............................................................................ 22 Example......................................................................... 22 Threads and Enqueue Contexts........................................................ 23 3

Enqueuing Dequeued Mail........................................................... 23 Dequeuing Messages................................................................... 23 Threads and Dequeue Contexts....................................................... 24 Message Processing Threads.......................................................... 24 String-valued Call Arguments........................................................... 25 Item Codes and Item Lists............................................................... 26 Chapter 2 MTA SDK Programming Considerations................................. 29 Running Your Enqueue and Dequeue Programs............................................ 29 Debugging Programs and Logging Diagnostics............................................ 31 Required Privileges..................................................................... 31 Compiling and Linking Programs........................................................ 32 Compiling.......................................................................... 32 Linking Instructions................................................................. 32 Running Your Test Programs............................................................ 32 Preventing Mail Loops when Re-enqueuing Mail........................................... 35 Miscellaneous Programming Considerations............................................... 36 Retrieving Error Codes............................................................... 36 Writing Output From a Channel Program.............................................. 36 Considerations for Persistent Programs................................................. 36 Refreshing Stale Configuration Information.......................................... 37 Keeping the Log File Available For Update........................................... 37 Chapter 3 Enqueuing Messages................................................. 39 Basic Steps to Enqueue Messages......................................................... 40 Originating Messages................................................................... 41 A Simple Example of Enqueuing a Message............................................... 41 Enqueuing a Message Example Output.............................................. 43 Transferring Messages into the MTA...................................................... 44 Intermediate Processing Channels........................................................ 44 Delivery Processing Options: Envelope fields.............................................. 45 Order Dependencies.................................................................... 45 Chapter 4 Dequeuing Messages................................................. 47 How Dequeuing Works................................................................. 48 Basic Dequeuing Steps.................................................................. 48 Caller-Supplied Processing Routine....................................................... 49 The process_message() Routine.......................................................... 52 A Simple Dequeue Example............................................................. 54 Explanatory Text for Numbered Comments.......................................... 57 Output from the Simple Dequeue Example........................................... 58 Processing the Message Queue........................................................... 58 4 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

The process_done() Routine............................................................. 60 A Complex Dequeuing Example......................................................... 61 Explanatory Text for Numbered Comments.......................................... 67 Output from the Complex Dequeue Example......................................... 69 Intermediate processing channels........................................................ 69 Preserve Envelope Information........................................................ 70 Use MTA_ENV_TO.................................................................. 70 Use Rewrite Rules to Prevent Message Loops........................................... 71 Intermediate Channel Example.......................................................... 71 Explanatory Text for Numbered Comments.......................................... 76 Sample Input Message for the Intermediate Channel Example.......................... 78 Output from the Intermediate Channel Example...................................... 78 Thread Creation Loop in mtadequeuestart................................................ 78 Multiple Calls to mtadequeuestart....................................................... 80 Calling Order Dependencies............................................................. 80 Chapter 5 Decoding Messages.................................................. 83 Usage Modes for mtadecodemessage()................................................... 83 The Input Source....................................................................... 85 Dequeue Context................................................................. 85 Caller-Supplied Input Routine...................................................... 85 The Inspection Routine................................................................. 86 A Simple Decoding Example............................................................ 87 Explanatory Text for Numbered Comments.......................................... 90 MIME Message Decoding Simple Example Output.................................... 91 The Output Destination................................................................. 91 Enqueue Context................................................................. 91 Caller-Supplied Output Routine.................................................... 92 Decode Contexts....................................................................... 92 A Simple Virus Scanner Example......................................................... 93 Example Option File............................................................. 104 Sample Input Message............................................................ 104 Explanatory Text for Numbered Comments......................................... 105 Decoding MIME Messages Complex Example Output................................ 106 Chapter 6 MTA SDK Reference................................................. 109 Summary of SDK Routines............................................................. 109 Address Parsing.................................................................... 110 Dequeue.......................................................................... 110 Enqueue.......................................................................... 111 Error Handling..................................................................... 111 Initialization....................................................................... 111 5

Logging and Diagnostics............................................................ 112 MIME Parsing and Decoding........................................................ 112 Miscellaneous...................................................................... 112 Option File Processing.............................................................. 113 MTA SDK Routines................................................................... 114 mtaaccountinglogclose............................................................... 115 mtaaddressfinish..................................................................... 116 mtaaddressgetn..................................................................... 116 mtaaddressparse..................................................................... 119 mtaaddresstochannel................................................................ 121 mtablocksize......................................................................... 124 mtachannelgetname.................................................................. 125 mtachanneltohost.................................................................... 127 mtadatetime......................................................................... 129 mtadebug............................................................................ 131 mtadecodemessage................................................................... 133 Inspection Routine............................................................... 135 Output Routine.................................................................. 136 Dequeue Context................................................................ 137 Caller-Supplied Input Routine..................................................... 137 Enqueue Context................................................................ 138 Caller-Supplied Output Routine................................................... 139 Decode Context Queries.......................................................... 140 Item Codes...................................................................... 141 mtadecodemessageinfoint............................................................. 143 mtadecodemessageinfoparams......................................................... 145 mtadecodemessageinfostring.......................................................... 147 mtadecodemessagepartcopy........................................................... 149 mtadecodemessagepartdelete.......................................................... 150 mtadequeueinfo...................................................................... 154 mtadequeuelinenext................................................................. 158 mtadequeuemessagefinish............................................................. 160 mtadequeuerecipientdisposition....................................................... 163 mtadequeuerecipientnext............................................................. 167 mtadequeuerewind................................................................... 169 mtadequeuestart..................................................................... 170 Other Considerations for mtadequeuestart............................................ 174 Multiple Calls to mtadequeuestart................................................. 175 Message Processing.............................................................. 175 Message Processing Procedure..................................................... 175 process_message Routine......................................................... 176 process_done() Routine........................................................... 178 Thread Creation Loop............................................................ 179 6 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

mtadequeuethreadid................................................................. 180 mtadone............................................................................. 181 mtaenqueuecopymessage............................................................. 181 mtaenqueueerror..................................................................... 183 mtaenqueuefinish.................................................................... 185 mtaenqueueinfo...................................................................... 187 mtaenqueuestart...................................................................... 191 mtaenqueueto....................................................................... 198 mtaenqueuewrite..................................................................... 204 mtaenqueuewriteline................................................................. 207 mtaerrno............................................................................. 209 mtainit............................................................................... 210 mtalog.............................................................................. 213 mtalogv............................................................................. 215 mtaoptionfinish...................................................................... 216 mtaoptionfloat....................................................................... 217 mtaoptionint......................................................................... 218 mtaoptionstart....................................................................... 220 mtaoptionstring...................................................................... 223 mtapostmasteraddress................................................................ 225 mtastacksize......................................................................... 227 mtastrerror.......................................................................... 228 mtauniquestring...................................................................... 228 mtaversionmajor..................................................................... 229 mtaversionminor..................................................................... 230 mtaversionrevision................................................................... 230 Part 2 Callable Send....................................................... 233 Chapter 7 Using Callable Send: mtasend........................................ 235 Sending a Message.................................................................... 235 Envelope and Header From: Addresses.................................................. 236 To:, Cc:, and Bcc: Addresses............................................................ 237 Message Headers and Content.......................................................... 238 Required Privileges.................................................................... 239 mtasenddispose...................................................................... 239 Compiling and Linking Programs....................................................... 240 Examples of Using mtasend............................................................ 240 Example 1: Sending a Simple Message................................................. 241 Example 1 Output............................................................... 242 Example 2: Specifying an Initial Message Header....................................... 242 7

Example 2 Input File............................................................. 243 Example 2 Output............................................................... 243 Example 3: Sending a Message to Multiple Recipients................................... 243 Example 3 Output............................................................... 245 Example 4: Using an Input Procedure to Generate the Message Body...................... 245 Chapter 8 mtasend Routine Specification........................................ 247 mtasend Syntax....................................................................... 249 Syntax............................................................................ 249 Arguments........................................................................ 249 Item Descriptor Fields............................................................... 250........................................................................ 250 Item Codes........................................................................... 251 MTA_ADR_NOSTATUS............................................................ 251 MTA_ADR_STATUS................................................................ 251 MTA_BCC......................................................................... 251 MTA_BLANK...................................................................... 251 MTA_CC.......................................................................... 252 MTA_CHANNEL.................................................................. 252 MTA_CFILENAME................................................................. 252 MTA_CFILENAME_NONE.......................................................... 252 MTA_CTYPE...................................................................... 252 MTA_ENC_BASE64................................................................ 253 MTA_ENC_BASE85................................................................ 253 MTA_ENC_BINHEX................................................................ 253 MTA_ENC_BTOA.................................................................. 253 MTA_ENC_COMPRESSED_BASE64.................................................. 253 MTA_ENC_COMPRESSED_BINARY................................................. 253 MTA_ENC_COMPRESSED_UUENCODE............................................. 254 MTA_ENC_HEXADECIMAL........................................................ 254 MTA_ENC_NONE................................................................. 254 MTA_ENC_PATHWORKS.......................................................... 254 MTA_ENC_QUOTED_PRINTABLE.................................................. 254 MTA_ENC_UNKNOWN............................................................ 254 MTA_ENC_UUENCODE............................................................ 255 MTA_END_LIST................................................................... 255 MTA_ENV_FROM................................................................. 255 MTA_ENV_TO..................................................................... 255 MTA_FRAGMENT_BLOCKS........................................................ 255 MTA_FRAGMENT_LINES.......................................................... 256 MTA_FROM....................................................................... 256 MTA_HDR_ADRS.................................................................. 256 MTA_HDR_BCC................................................................... 257 8 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

MTA_HDR_CC.................................................................... 257 MTA_HDR_FILE................................................................... 257 MTA_HDR_LINE.................................................................. 257 MTA_HDR_NOADRS.............................................................. 257 MTA_HDR_NORESENT............................................................ 258 MTA_HDR_PROC.................................................................. 258 MTA_HDR_RESENT............................................................... 258 MTA_HDR_TO.................................................................... 258 MTA_HDRMSG_FILE.............................................................. 258 MTA_HDRMSG_PROC............................................................. 259 MTA_IGNORE_ERRORS............................................................ 259 MTA_INTERACTIVE............................................................... 259 MTA_ITEM_LIST.................................................................. 259 MTA_MAX_TO.................................................................... 259 MTA_MODE_BINARY.............................................................. 259 MTA_MODE_TEXT................................................................ 260 MTA_MSG_FILE................................................................... 260 MTA_MSG_PROC.................................................................. 260 MTA_NOBLANK.................................................................. 260 MTA_NOIGNORE_ERRORS......................................................... 261 MTA_PRIV_DISABLE_PROC........................................................ 261 MTA_PRIV_ENABLE_PROC........................................................ 261 MTA_SUBADDRESS................................................................ 261 MTA_SUBJECT.................................................................... 262 MTA_TO.......................................................................... 262 MTA_USER....................................................................... 262 Appendix A Error Status Codes Summary....................................... 263 Glossary.................................................................... 267 Index........................................................................ 271 9

10 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

About This Manual This manual describes the Sun Open Net Environment (ONE) Messaging Server 6.0 Message Transfer Agent (MTA) Software Development Kit (SDK) and Callable Send facility. Topics covered in this chapter include: Who Should Read This Manual What You Need to Know How This Manual is Organized Document Conventions Where to Find Related Information Where to Find This Manual Online Related Third-Party Web Site References Who Should Read This Manual While this document is primarily intended for system programmers writing mail software, system managers wishing to become more familiar with the inner workings of the MTA may also benefit from a casual reading of this manual. Programmers wishing to write gateways or channels should use the MTA SDK. Programmers writing code merely to send mail will probably find the Callable Send facility sufficient for their needs. 11

What You Need to Know What You Need to Know A working knowledge of the following material is essential to programmers writing software that will create electronic mail messages with the MTA SDK: Sun ONE Messaging Server RFC 2822 - the successor to RFCs 822 and 1123 Understanding this RFC is essential for programmers writing software that creates electronic mail messages with this SDK. RFCs 2045, 2046, 2047, and 2049 These RFCs are useful for programmers interested in creating MIME compliant messages. How This Manual is Organized This manual describes two distinct interfaces. Each interface has an introductory chapter and a reference chapter and corresponding appendixes. This manual contains the following chapters: About This Manual (this chapter) Part 1, MTA SDK Chapter 1, MTA SDK Concepts and Overview Chapter 2, MTA SDK Programming Considerations Chapter 3, Enqueuing Messages Chapter 4, Dequeuing Messages Chapter 5, Decoding Messages Chapter 6, MTA SDK Reference Part 2, Callable Send Chapter 7, Using Callable Send: mtasend Chapter 8, mtasend Routine Specification Appendix A, Error Status Codes Summary Glossary 12 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

Document Conventions Document Conventions Monospaced Font Monospaced font is used for any text that appears on the computer screen or text that you should type. It is also used for filenames, distinguished names, functions, and examples. Italicized Font Italicized font is used to represent text that you enter using information that is unique to your installation (for example, variables). It is used for server paths and names. For example, throughout this document you will see path references of the form: msg_svr_base/... The Messaging Server Base (msg_svr_base) represents the directory path in which you install the server. The default value of the msg_svr_base is /opt/sunwmsgsr. Square or Straight Brackets Square (or straight) brackets [] are used to enclose optional parameters. Platform-specific Syntax All paths specified in this manual are in UNIX format. Where to Find Related Information In addition to this manual, Messaging Server comes with supplementary information for administrators as well as documentation for end users and developers. Use the following URL to see all the Messaging Server documentation: http://docs.sun.com/coll/s1_messagingserver_60 Listed below are the documents that are available: About This Manual 13

Where to Find This Manual Online Sun ONE Messaging Server Installation Guide Sun ONE Messaging Server Release Notes Sun ONE Messaging Server Administrator s Guide Sun ONE Messaging Server Reference Manual Sun ONE Messaging and Collaboration Schema Reference Manual Sun ONE Messaging Server Provisioning Guide Sun ONE Messaging and Collaboration Event Notification Service Manual Sun ONE Messaging Server Messenger Express Customization Guide Sun ONE Messaging Server MTA Programmer s Reference Manual The Sun ONE Messaging Server product suite contains other products such as Sun ONE Console, Directory Server, and Administration Server. Documentation for these and other products can be found at the following URL: http://docs.sun.com/db/prod/sunone In addition to the software documentation, see the Sun ONE Messaging Server Software Forum for technical help on specific Messaging Server product questions. The forum can be found at the following URL: http://swforum.sun.com/jive/forum.jsp?forum=15 Where to Find This Manual Online You can find the Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual online in PDF and HTML formats. This book can be found at the following URL: http://docs.sun.com/doc/816-6742-10 14 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

Related Third-Party Web Site References Related Third-Party Web Site References Third-party URLs are referenced in this document and provide additional, related information. NOTE Sun is not responsible for the availability of third-party Web sites mentioned in this document. Sun does not endorse and is not responsible or liable for any content, advertising, products, or other materials that are available on or through such sites or resources. Sun will not be responsible or liable for any actual or alleged damage or loss caused by or in connection with the use of or reliance on any such content, goods, or services that are available on or through such sites or resources. About This Manual 15

Related Third-Party Web Site References 16 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

Part 1 MTA SDK Chapter 1, MTA SDK Concepts and Overview Chapter 2, MTA SDK Programming Considerations Chapter 3, Enqueuing Messages Chapter 4, Dequeuing Messages Chapter 5, Decoding Messages Chapter 6, MTA SDK Reference 17

18 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

Chapter 1 MTA SDK Concepts and Overview The Sun ONE Messaging Server MTA SDK is a low-level interface, with routines falling into three categories: those that enqueue messages, those that dequeue messages, and miscellaneous routines that typically query or set MTA states, or parse message structures, such as lists of RFC 822 addresses. The Callable Send facility, described in Chapter 5 and Chapter 6 and used only for originating mail from the local host, can be used simultaneously with the MTA SDK. This chapter contains the following topics: Channel Programs and Message Queuing on page 19 Managing Multiple Threads: Contexts on page 20 Enqueuing Messages on page 20 Dequeuing Messages on page 23 String-valued Call Arguments on page 25 Item Codes and Item Lists on page 26 Channel Programs and Message Queuing Message enqueuing and dequeuing are generally done by channel programs also referred to simply as channels. There are two types of channel programs, master channel that dequeue messages, and channels (sometimes referred to as slave channels) that enqueue messages. Each MTA channel has its own message queue, referred to as a channel queue. Channel programs may also perform intermediate 19

Managing Multiple Threads: Contexts roles by dequeuing messages from one message queue and re-enqueuing them to another while, typically, processing the message at the same time. For example, the message processing might be to convert the message body from one format to another. Managing Multiple Threads: Contexts A number of SDK operations require multiple, sequential calls to the SDK routines. To manage this, the SDK provides the caller with a pointer to an opaque data structure called a context. This mechanism allows for management of state information across calls to the SDK. Use of the contexts allows multiple threads within a single program to make simultaneous calls to the same SDK routine. The only limitation is that a single, specific context may not be simultaneously used by different threads in calls to the SDK. When such usage is detected in an SDK call, an MTA_THREAD error results. In some cases these contexts are automatically created for you, such as dequeue and decode contexts. In all other cases, for example for enqueue contexts, you must make an explicit call to create them. The calls that automatically create contexts also automatically dispose of them. In all other cases, a call must be made to explicitly dispose of a context. It is important to dispose of contexts when you no longer need them as so doing releases resources such as virtual memory. For more information on contexts, see Threads and Enqueue Contexts on page 23, and Threads and Dequeue Contexts on page 24. Enqueuing Messages Messages are introduced to the MTA by enqueuing them. Each enqueued message contains two required components, the message envelope and the message header, and may optionally contain a third component, the message body. The contents of the envelope and header must be provided by the program using the SDK. For instructions on how to enqueue messages, see Chapter 2, MTA SDK Programming Considerations. For an example of how to enqueue a message, see Code Example 3-1 on page 42. 20 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

Enqueuing Messages Message Components This section describes the three message components: envelope, header and body. Envelope The message envelope contains the envelope From: address, and the list of envelope To: addresses. The envelope is created by the SDK as the message is enqueued. The addresses to be placed in the envelope must conform to RFC 2822. The envelope To: addresses are often referred to as envelope recipient addresses. Programs should rely solely upon the MTA SDK routines to read and write envelope information, since the queued message file formats are subject to change. Using the SDK routines insulates programmers from format changes. The routines mtaenqueuestart() and mtaenqueueto() are used to construct a message envelope. Header The message header contains RFC 2822 style header lines. The program enqueuing the message has nearly complete control over the contents of the header and can specify as many or as few header lines as it sees fit, with a few exceptions. A header must have at a minimum three lines: From:, Date:, and at least one recipient header line, such as To:, Cc:, or Bcc:. As the message is enqueued, the SDK will do its best to supply any mandatory header lines that are missing as well as take some measures to ensure that the contents of the header lines conform to any relevant standards. If the From: header line is omitted by the program using the SDK, the SDK code will construct a default header line from the envelope From: address. This may not always be appropriate; for instance, when mail is addressed to a mailing list that specifies an Errors-to: address, then the Errors-to: address should be used as the envelope From: address. In this case, it is not appropriate to derive the header From: line from the envelope From: address. If the Date: header line is omitted, the SDK code will supply it, as well as a Date-warning: header line. Finally, if no recipient header lines are present, then the SDK code will generate them using the envelope recipient addresses. Any addresses appearing in the message header should conform to RFC 2822. The header is written line-by-line using the routines mtaenqueuewrite() and mtaenqueuewriteline(). Chapter 1 MTA SDK Concepts and Overview 21

Enqueuing Messages Body The optional message body contains the content of the message. As with the message header, the program enqueuing the message has nearly complete control over the contents of the message body. The only exception to this is when the message is structured with multiple parts or requires encoding, for example if it contains binary data, or lines requiring wrapping. In such cases, the SDK will ensure that the message body conforms to MIME standards (RFCs 2045 2049). As with the message header, message body lines are written with the routines mtaenqueuewrite() and mtaenqueuewriteline(). Example Enqueued messages may be seen in the MTA queue directories and are merely ASCII text files. In the following sample message, lines 1 and 2 are the message envelope, the next four lines are the header, and the rest of the lines are the body. jdoe@siroe.com msmith@siroe.com Date: Tues, 1 Apr 2003 15:01 PST From: John Doe To: Mike Smith Subject: Lunch today Mike, Just confirming our lunch appointment today I ll meet you at the restaurant at noon. John NOTE As stated earlier, do not directly read from or write messages to the MTA message queues. Always use the SDK routines or Callable Send. The file structure of messages in the MTA queues are subject to change. In addition, site specific constraints may be placed on things such as encodings, and character set usage. The SDK routines automatically handle these and other issues. 22 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

Dequeuing Messages Threads and Enqueue Contexts Each individual message being enqueued to the MTA is represented within the SDK by an opaque enqueue context of type mta_nq_t. This enqueue context is created by mtaenqueuestart() and destroyed by mtaenqueuefinish(). Throughout the enqueue process, the message being enqueued is referenced through its enqueue context. A program using the SDK may simultaneously enqueue multiple messages, each message represented by its own enqueue context. Indeed, multiple threads may simultaneously enqueue one or more messages per thread. The only requirement is that a specific enqueue context not be simultaneously used by two or more threads. In the event that the SDK detects simultaneous usages, it returns the MTA_THREAD error. Enqueuing Dequeued Mail If a message being enqueued is the result of dequeuing a message, then all envelope fields can automatically be carried over from the old message to the new message. Both per-message fields (such as envelope IDs) and per-recipient fields (such as delivery receipt requests) can be preserved. This preservation is achieved by supplying the associated dequeue context to the routines mtaenqueuestart(),or mtaenqueueto(), or both. Supplying the dequeue context to mtaenqueuestart() preserves per-message envelope fields, while supplying the dequeue context to mtaenqueueto() preserves the per-recipient fields for the specified envelope recipient. For information on message dequeuing and message dequeue contexts, see Dequeuing Messages on page 23. Dequeuing Messages Messages stored in the MTA message queues are removed from their queues by dequeuing them. This is typically done by channel programs (see Channel Programs and Message Queuing on page 19). When a message is dequeued, it is literally removed from the MTA message queues and, as far as the MTA is concerned, no longer exists. That is, dequeuing a message relieves the MTA of all further responsibility for the message the responsibility is assumed to have been passed on to some other entity such as another MTA or a message store. Chapter 1 MTA SDK Concepts and Overview 23

Dequeuing Messages The channel name used by the program identifies the MTA message queue being serviced by the program. The channel name can either be explicitly specified by the program or determined from the run time environment using the PMDF_CHANNEL environment variable. NOTE Channel naming conventions: the name must be 32 bytes or less, should be in lower case, and if the channel will have multiple instantiations, then it should be given a generic name, such as tcp, and then each instantiation can be given a specific version of it, such as tcp_local, tcp_auth, tcp_intranet. Multiple programs may simultaneously process the same message queue. The SDK and Job Controller will automatically coordinate such efforts, using file locks to prevent two or more programs or threads from simultaneously processing the same message. When the message processing program (see Dequeue Message Processing Routine Tasks on page 50) is called, the message to be processed is locked so that no other jobs may access that message. The message is then unlocked when mtadequeuemessagefinish() is called, or when the program exits, normally or abnormally. Threads and Dequeue Contexts Each individual message being dequeued from the MTA is represented within the SDK by an opaque dequeue context of type mta_dq_t. Each dequeue context is created by mtadequeuestart() and passed to a caller-supplied processing procedure. Each dequeue context is then destroyed when mtadequeuemessagefinish() is called. Throughout the dequeue process, the message being dequeued is referenced through its dequeue context. Under typical usage, a program will have multiple threads operating, each simultaneously dequeuing a message. However, it is not permitted for two threads to simultaneously use the same dequeue context in calls to the SDK. In the event the SDK detects simultaneous usages, it returns the MTA_THREAD error. Message Processing Threads When mtadequeuestart() is called, a communication path with the MTA Job Controller is established. The Job Controller is then asked if there are messages to be processed for the channel. Typically there will be messages to process since the Job Controller normally only starts channel programs when there are queued 24 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003

String-valued Call Arguments messages in need of processing. Based upon information obtained from the Job Controller, mtadequeuestart() will then begin to create non-joinable processing threads. Each processing thread immediately begins processing the queued messages. For further information about the exact steps a message processing thread goes through, see Debugging Programs and Logging Diagnostics on page 31 String-valued Call Arguments Strings passed as call arguments to the MTA SDK routines also have an associated length argument. Use of the length argument is optional; that is, if you do not know the length or do not wish to supply it, then supply a value of zero for the length argument. However, in that case the supplied string must be NULL terminated so that the SDK routine can determine the string s length. When a non-zero length is supplied, then the string does not need to be NULL terminated. Wherever possible, the SDK routines return pointers to output strings rather than returning the strings themselves. These pointers are always thread safe; however, when associated with an SDK context they often are only valid as long as the context itself is valid. Such limits will be noted in the description of the individual routines in Chapter 4, Dequeuing Messages. In some cases, an output string buffer must be supplied, as with the mtadatetime() and mtauniquestring() routines. It is worthwhile to note that internally, the MTA has several basic string sizes. Users of the SDK generally do not need to concern themselves with this fact. However, at times it may be helpful to be aware of them as they can provide an upper bound on the length of various strings you might encounter. As shown in the following table, for instance, channel names will never be longer than CHANLENGTH bytes; channel option values will never exceed a length of BIGALFA_SIZE bytes; and envelope addresses will never exceed a length of ALFA_SIZE bytes: Symbolic Names Value in Bytes Typical Usage ALFA_SIZE 256 Upper limit on the length of an address BIGALFA_SIZE 1024 Upper limit on the length of message line and channel option value CHANLENGTH 32 Upper limit on the length of a channel name Chapter 1 MTA SDK Concepts and Overview 25

Item Codes and Item Lists Item Codes and Item Lists Fields A number of the MTA SDK routines accept a variable length list of item code arguments. For instance, mtainit() has the call syntax: int mtainit(int item_code,...) That is to say, it accepts one or more integer-valued call arguments. These call arguments are referred to as an "item code list" or, more simply, an "item list". Each item list must be terminated by a call argument with the value 0. As such, the call syntax for mtainit() can be expressed as int mtainit([int item_code[,...]], 0) There can be zero or more item codes with non-zero values which must then be followed by an item code with the value zero. In the MTA SDK, item lists serve two purposes. First, they allow code using the SDK to specify optional behaviors and actions to the SDK. Second, they provide an extension mechanism for future versions of the SDK to extend the functionality of routines through the introduction of new item codes. However, there is a drawback to the use of item lists; the number of items passed to an SDK routine must be known at compile time. That is, it is difficult if not impossible for a program at run time to adjust the number of item codes that it wishes to pass. In recognition of this limitation, all SDK routines that accept an item code list also accept a pointer to an arbitrary length array of item codes. Such an array is referred to as an "item list array" and is specified with the MTA_ITEM_LIST item code. This mechanism allows programs to dynamically construct the array at run time, while still using a fixed number of arguments at compile time. The MTA_ITEM_LIST item code is always followed by an additional call argument whose value is a pointer to an array of mta_item_list_t type elements. Each array entry has the following five fields: int item_code An item code value indicating an action to be effected. The permitted item code values are routine specific. const void *item_address The caller-suppled address of data to be used in conjunction with the action specified by the item_code field. Not all actions require use of this field. size_t item_length When the item code has an associated string value, this field optionally provides the length in bytes of the string, not including any NULL terminator. If a value of zero is supplied, then the string pointed at by the item_address field must be NULL terminated. When the item code has an associated integral value, this field supplies that value. Not all actions require the use of this field. 26 Sun ONE Messaging Server 6.0 MTA Programmer s Reference Manual December 2003