Everhart,Glenn From: vandenheuvel@eps.enet.dec.c*m Sent: Monday, May 11, 1998 7:58 AM To: Info-VAX@Mvb.Saic.Com Subject: Re: E-Mail and "C" program. In article <6ifcc4$1bk$1@ligarius.ultra.net>, "Peter Chandler" writes... >Hi All, > >I am looking for an example of how to send E-Mail >from within a "C" program on VMS. Found this in my stash... Untested... Good luck, Hein. #include #include #include #include #include typedef struct itmlst { short buffer_length; short item_code; long buffer_address; long return_length_address; } ITMLST; int send_context = 0 ; ITMLST nulllist[] = { {0,0,0,0} }; int getline(char *line, int max) { if (fgets(line, max, stdin) == NULL) return 0; else return strlen(line); } int main (int argc, char *argv[]) { char to_user[NAM$C_MAXRSS], subject_line[NAM$C_MAXRSS], file[NAM$C_MAXRSS], resultspec[NAM$C_MAXRSS] ; long resultspeclen; int status = SS$_NORMAL, file_len = 0, subject_line_len = 0, to_user_len = 0 ; ITMLST address_itmlst[] = { {sizeof(to_user), MAIL$_SEND_USERNAME, to_user, &to_user_len}, {0,0,0,0}}, bodypart_itmlst[] = { {sizeof(file), MAIL$_SEND_FILENAME, file, &file_len}, {0,0,0,0}}, out_bodypart_itmlst[] = { {sizeof(resultspec), MAIL$_SEND_RESULTSPEC, resultspec, &resultspeclen}, {0,0,0,0}}, attribute_itmlst[] = { {sizeof(to_user), MAIL$_SEND_TO_LINE, to_user, &to_user_len}, {sizeof(subject_line), MAIL$_SEND_SUBJECT, subject_line, &subject_line_len}, /* {0, MAIL$_SEND_FOREIGN, 0, 0},*/ {0,0,0,0}} ; status = mail$send_begin(&send_context, &nulllist, &nulllist); if (status != SS$_NORMAL) exit(status); /* Get the destination and add it to the message */ printf("To: "); to_user[getline(to_user, NAM$C_MAXRSS) - 1] = NULL; address_itmlst[0].buffer_length = strlen(to_user); address_itmlst[0].buffer_address = to_user; status = mail$send_add_address(&send_context, address_itmlst, &nulllist); if (status != SS$_NORMAL) return(status); /* Get the subject line and add it to the message header */ printf("Subject: "); subject_line[getline(subject_line, NAM$C_MAXRSS) - 1] = NULL; /* Displayed TO: line */ attribute_itmlst[0].buffer_length = strlen(to_user); attribute_itmlst[0].buffer_address = to_user; /* Subject: line */ attribute_itmlst[1].buffer_length = strlen(subject_line); attribute_itmlst[1].buffer_address = subject_line; status = mail$send_add_attribute(&send_context, attribute_itmlst, &nulllist); if (status != SS$_NORMAL) return(status); /* Get the file to send and add it to the bodypart of the message */ printf("File: "); file[getline(file, NAM$C_MAXRSS) - 1] = NULL; bodypart_itmlst[0].buffer_length = strlen(file); bodypart_itmlst[0].buffer_address = file; status = mail$send_add_bodypart(&send_context, bodypart_itmlst, out_bodypart_itmlst); if (status != SS$_NORMAL) return(status); resultspec[resultspeclen] = '\0'; printf("Full file spec actually sent: [%s]\n", resultspec); /* Send the message */ status = mail$send_message(&send_context, nulllist, nulllist); if (status != SS$_NORMAL) return(status); /* Done processing witht the SEND context */ status = mail$send_end(&send_context, nulllist, nulllist); if (status != SS$_NORMAL) return(status); return (status);