/* * @(#)enqueue_a_message.c 1.7 06/22/98 SMI * * Copyright 1997 by Sun Microsystems, Inc. * All rights reserved * * Send a "Hello world!" message from a specified originator to * a specified recipient * * Syntax: * enqueue_a_message -t recipient_address [-f from_address] */ #include #include #include #include imme_t me; void check ( char *func, int status) { if ( status != 0 ) { printf( "ERROR %d in %s: %s\n", status, func, (char *)imta_error( status)); imme_abort(me); imta_end(); exit (status); } return; } static void usage() { printf("Usage:\n enqueue_a_message -c channel -t recipient_address [-f from_address]\n\n"); return; } main ( int argc, char **argv) { char *body, *channel = NULL; char rcpt[256], orig[256]; char date_header[256]; imhdr_t hdr; char c; /* interpret the command line */ *orig = *rcpt = 0; while ((c = getopt(argc, argv, "t:f:c:")) != EOF) { switch (c) { case 'c': /* the recipient */ channel = (char *)strdup( optarg); break; case 't': /* the recipient */ strcpy( rcpt, optarg); break; case 'f': /* the originator */ strcpy( orig, optarg); break; default: usage(); exit( EX_USAGE); } } /* if the originator is not set, set it to the postmaster */ if ( *orig == 0 ) { strcpy( orig, "postmaster"); } if ( *rcpt == 0 || channel == NULL ) { usage(); exit( EX_USAGE); } /* initialize */ check( "imta_init", imta_init(channel)); check( "imme_init", imme_init(&me)); /* create the envelope */ check( "imme_start_envelope", imme_start_envelope( me, orig)); check( "imme_add_recipient", imme_add_recipient( me, 0, 0, rcpt, NULL)); /* the header */ imhdr_alloc(&hdr); imhdr_add_line(&hdr, HL_SUBJECT, "Hello world!", 0); imhdr_add_line(&hdr, HL_MIME_VERSION, "1.0", 0); imhdr_add_line(&hdr, HL_CONTENT_TYPE, "TEXT/PLAIN; CHARSET=US-ASCII", 0); check( "imme_write_header", imme_write_header( me, hdr)); imhdr_free(hdr); /* and the body */ check( "imme_write_text", imme_write_text( me, "Hello World!\r\n")); /* Now, send it */ check( "imme_enqueue", imme_enqueue( me)); imme_end(me); imta_end(); exit(EX_OK); }