gtpc2m4pC/C++ Language Support User's Guide

mail-Process Internet Mail

This function allows you to process Internet mail, also known as electronic mail (e-mail), on the TPF Internet mail server. See TPF Transmission Control Protocol/Internet Protocol for more information about TPF Internet mail server support.

Format

#include  <tpf_mail.h>
void      mail(char   flag,
               char **rcpt,
               char  *path,
               char  *dmn,
               char  *uid,
               char  *pw,
               int    rc);

flag
The function that you want to perform. Specify one of the following values:

'e'
Checks if there is available mail to read.

'r'
Reads Internet mail from the TPF Internet mail server and stores it in the file on the TPF file system specified by path.

'g'
Reads Internet mail from the TPF Internet mail server and stores it in the TPF database. The file address of where the mail is stored is returned in the rc parameter.

'w'
Sends Internet mail from the file specified by path to the TPF Internet mail server.

'p'
Sends Internet mail from a file address specified by path to the TPF Internet mail server.

rcpt
A pointer to an array of pointers. Each pointer in the array points to a character string that contains the Internet mail address of the recipient. In the array, specify a NULL pointer to indicate the end of the recipient list.

This parameter applies only when the value for flag is 'w' or 'p'. Specify NULL for this parameter when the value for flag is 'r', 'g', or 'e'.

path
A pointer to a character string that contains the path name of a file or a file address. The value for path depends on the value you specify for flag, as follows:

dmn
A pointer to a character string that contains the name of the mail domain in which you have an Internet mail account.

uid
A pointer to a character string that contains your Internet mail account name.

pw
A pointer to a character string that contains the password for your Internet mail account.

rc
The return code. See Normal Return and Error Return for more information.

Normal Return

rc is one of the following values:

0
One of the following:

1
One of the following:

fileaddr
The file address of where the mail is stored. This is returned if the value specified for flag was 'g' and the function was completed successfully.

Error Return

The value of rc is -1 and errno is set to the following:

MAIL_ERRNO
The TPF Internet mail server detected a protocol error.

Programming Considerations

Examples

An Internet mail message is processed in the following example. In this example:

/*
  Build an Internet mail message &
  Send an Internet mail message
*/
 
#include <stdio.h>
#include <stdlib.h>
#include <tpf_mail.h>
#include <string.h>
 
#define ERROR -1
#define OK 0
 
int build_message(char *mail_message);
 
void main()
{
   int  rc=0;
   char *rcpt[3];
   char mail_message[] = "/temp/file";
   char readmail_message[] = "/temp/mailin";
   char dmn[] = "tpf.com";
   char uid[] = "curly";
   char pw[] = "shemp3";
 
   rcpt[0]="moe@tpf.com";
   rcpt[1]="larry@tpf2.com";
   rcpt[2]=(char*)NULL;
 
   if((rc=build_message(mail_message)) == OK)
   {
      mail('w',rcpt,mail_message,dmn,uid,(char*)NULL,rc);
	        if(rc==0)printf("Message sent\n");
	        else{
	           printf("Message not sent\n");
	    }
   }
   else{
      printf("ERROR OCCURRED: CHECK ERRNO");
   }
 
   mail('e',(char*)NULL,(char*)NULL,dmn,uid,pw,rc);
   if (rc==0)
   {
    mail('r',(char*)NULL,readmail_message,uid,pw,rc);
   }
}
 
int build_message(char *mail_message)
{
   FILE* in;
   char content[]="Dear Moe\n\nHow's it going.\n\nRegards Curly.\n";
   int ret=OK;
 
   if((in=fopen(mail_message,"w"))==(FILE*)NULL)
   {
      fprintf(stderr,"Can't open message file: %s.\n",mail_message);
      return(ERROR);
   }
   fprintf(in,"%s",content);
   return OK;
}

The following example shows how you can process an Internet mail message using file addresses on the TPF database. In this example:

/*
  Build an Internet mail message &
  Send an Internet mail message
*/
 
#include <stdio.h>
#include <stdlib.h>
#include <tpf_mail.h>
#include <string.h>
 
#define ERROR -1
#define OK 0
 
int build_message(char *);
 
void main()
{
   int  rc=0;
   char *rcpt[3];
   char mail_message[16];
   char dmn[] = "tpf.com";
   char uid[] = "curly";
   char pw[] = "shemp3";
 
   rcpt[0]="moe@tpf.com";
   rcpt[1]="larry@tpf2.com";
   rcpt[2]=(char*)NULL;
 
   mail_message[0]='\0';
 
   if((rc=build_message(mail_message)) == OK)
   {
      mail('p',rcpt,mail_message,dmn,uid,(char*)NULL,rc);
	        if(rc==0)printf("Message sent\n");
	        else{
	           printf("Message not sent\n");
	    }
   }
   else{
      printf("ERROR OCCURRED: CHECK ERRNO");
   }
 
   mail('e',(char*)NULL,(char*)NULL,dmn,uid,pw,rc);
   if (rc==0)
   {
    mail('g',(char*)NULL,(char*)NULL,uid,pw,rc);
   }
}
 
int build_message(char *msg_FA)
{
    unsigned int fa;
    message_record *msgrec;
 
    fa = getfc(D8, GETFC_TYPE0, "\xFC\x60",                        /
               (int)(GETFC_BLOCK+GETFC_FILL),GETFC_NOSERRC,0x00);
 
    sprintf(msg_FA,"%d",fa);
 
    ecbptr()->ebcid8 = 0XFC60;
    msgrec = ( message_record *) ecbptr()->ebccr8;
 
    if (msgrec == NULL)
       return (ERROR);
 
    msgrec->MR0RID = 0XFC60;
    strcpy(&msgrec->msg_data,"Hi! How are you today?\n");
    return OK;
}

Related Information