/** * \fn msiSendMail(msParam_t* xtoAddr, msParam_t* xsubjectLine, msParam_t* xbody, ruleExecInfo_t *rei) * * \brief Sends email * * \module core * * \since pre-2.1 * * \author Arcot Rajasekar * \date 2008-05 * * \note This microservice sends e-mail using the mail command in the unix system. No attachments are supported. The sender of the e-mail is the unix user-id running the irodsServer. * * \usage See clients/icommands/test/rules3.0/ * * \param[in] xtoAddr - a msParam of type STR_MS_T which is an address of the receiver. * \param[in] xsubjectLine - a msParam of type STR_MS_T which is a subject of the message. * \param[in] xbody - a msParam of type STR_MS_T which is a body of the message. * \param[in,out] rei - The RuleExecInfo structure that is automatically * handled by the rule engine. The user does not include rei as a * parameter in the rule invocation. * * \DolVarDependence none * \DolVarModified none * \iCatAttrDependence none * \iCatAttrModified none * \sideeffect An e-mail sent to the specified recipient. * * \return integer * \retval 0 on success * \pre none * \post none * \sa none **/ int msiSendMail( msParam_t* xtoAddr, msParam_t* xsubjectLine, msParam_t* xbody, ruleExecInfo_t* ) { char *mailStr = 0; char fName[100]; char *t1 = 0, *t2 = 0; FILE *fd = 0; char *toAddr = 0; char *subjectLine = 0; char *body = 0; int status = 0; toAddr = ( char * ) xtoAddr->inOutStruct; subjectLine = ( char * ) xsubjectLine->inOutStruct; body = ( char * ) xbody->inOutStruct; status = checkStringForEmailAddress( toAddr ); if ( status ) { rodsLog( LOG_NOTICE, "checkStringForEmailAddress failed for [%s]", toAddr ); return status; } status = checkStringForSystem( subjectLine ); if ( status ) { rodsLog( LOG_NOTICE, "checkStringForSystem failed for [%s]", subjectLine ); return status; } if ( reTestFlag > 0 ) { if ( reTestFlag == COMMAND_TEST_1 ) { fprintf( stdout, " Sending Email\n To:%s\n Subject:%s\n Body:%s\n", toAddr, subjectLine, body ); } else if ( reTestFlag == HTML_TEST_1 ) { fprintf( stdout, "Sending Email\n<UL>\n" ); fprintf( stdout, "<LI>To: %s\n", toAddr ); fprintf( stdout, "<LI>subjectLine: %s\n", subjectLine ); fprintf( stdout, "<LI>Body: %s\n", body ); fprintf( stdout, "</UL>\n" ); } else if ( reTestFlag == LOG_TEST_1 ) rodsLog( LOG_NOTICE, " Calling msiSendMail To:%s Subject %s\n", toAddr, subjectLine ); if ( reLoopBackFlag > 0 ) { return 0; } } sprintf( fName, "mailFile%d.ml", getpid() ); fd = fopen( fName, "w" ); if ( fd == NULL ) { return FILE_CREATE_ERROR; } t1 = body; #ifdef solaris_platform if ( subjectLine != NULL && strlen( subjectLine ) > 0 ) { fprintf( fd, "Subject:%s\n\n", subjectLine ); } #endif while ( t1 != NULL ) { if ( ( t2 = strstr( t1, "\\n" ) ) != NULL ) { *t2 = '\0'; } fprintf( fd, "%s\n", t1 ); if ( t2 != NULL ) { *t2 = '\\'; t1 = t2 + 2; } else { t1 = NULL; } } fclose( fd ); mailStr = ( char* )malloc( strlen( toAddr ) + strlen( subjectLine ) + 100 ); if ( mailStr == NULL ) { return SYS_MALLOC_ERR; } #ifdef solaris_platform sprintf( mailStr, "cat %s| mail '%s'", fName, toAddr ); #else /* tested for linux - not sure how other platforms operate for subject */ if ( subjectLine != NULL && strlen( subjectLine ) > 0 ) { sprintf( mailStr, "cat %s| mail -s '%s' '%s'", fName, subjectLine, toAddr ); } else { sprintf( mailStr, "cat %s| mail '%s'", fName, toAddr ); } #endif int ret = 0; ret = system( mailStr ); if ( ret ) { irods::log( ERROR( ret, "mailStr command returned non-zero status" ) ); } sprintf( mailStr, "rm %s", fName ); ret = system( mailStr ); if ( ret ) { irods::log( ERROR( ret, "mailStr command returned non-zero status" ) ); } free( mailStr ); return 0; }
void UnixSendEmail( char *toAddr, char *subjectLine, char *msgBody ) { char fileName[1024]; char mailStr[100]; FILE *fd; int t; char *t1, *t2; if ( ( toAddr == NULL ) || ( strlen( toAddr ) == 0 ) ) { return; } srand( time( 0 ) ); t = rand() % 281; sprintf( fileName, "/tmp/rodstmpmail%d.txt", t ); fd = fopen( fileName, "w" ); if ( fd == NULL ) { return; } #ifdef solaris_platform if ( ( subjectLine != NULL ) && ( strlen( subjectLine ) > 0 ) ) { fprintf( fd, "Subject:%s\n\n", subjectLine ); } #endif t1 = msgBody; while ( t1 != NULL ) { if ( ( t2 = strstr( t1, "\\n" ) ) != NULL ) { *t2 = '\0'; } fprintf( fd, "%s\n", t1 ); if ( t2 != NULL ) { *t2 = '\\'; t1 = t2 + 2; } else { t1 = NULL; } } fclose( fd ); #ifdef solaris_platform sprintf( mailStr, "cat %s| mail %s", fileName, toAddr ); #else /* tested for linux - not sure how other platforms operate for subject */ if ( ( subjectLine != NULL ) && ( strlen( subjectLine ) > 0 ) ) { if ( checkStringForSystem( fileName ) ) { return; } if ( checkStringForSystem( subjectLine ) ) { return; } if ( checkStringForEmailAddress( toAddr ) ) { return; } sprintf( mailStr, "cat %s| mail -s '%s' %s", fileName, subjectLine, toAddr ); } else { if ( checkStringForSystem( fileName ) ) { return; } if ( checkStringForEmailAddress( toAddr ) ) { return; } sprintf( mailStr, "cat %s| mail %s", fileName, toAddr ); } #endif int ret = 0; ret = system( mailStr ); if ( ret ) { irods::log( ERROR( ret, "mailStr command returned a non-zero value." ) ); } sprintf( mailStr, "rm %s", fileName ); ret = system( mailStr ); if ( ret ) { irods::log( ERROR( ret, "mailStr command returned a non-zero value." ) ); } }