The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to send email from HP Unix box eurouno UNIX for Dummies Questions & Answers 3 12-03-2007 04:56 PM
How to Send email in UNIX cooolthud Shell Programming and Scripting 1 01-23-2007 05:49 AM
Send email where # is in the email address - Using Unix jingi1234 UNIX for Dummies Questions & Answers 1 05-23-2005 08:23 AM
Send email from unix terminal on Mac OS 10.x hypamw UNIX for Dummies Questions & Answers 0 05-03-2005 08:26 PM
Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win) Vetrivela UNIX for Advanced & Expert Users 2 02-15-2005 07:43 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-26-2006
whatisthis's Avatar
Registered User
 

Join Date: Aug 2004
Posts: 175
Red face Can we send email with C program on Unix?

Hi,
I just wanted to know if there is any way to send email using C program on Unix.

Thanks for your help!

Julie
Reply With Quote
Forum Sponsor
  #2  
Old 06-26-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 988
Yes. They can go the easy way and execute sendmail using system("sendmail ..."), or it can connect to mail servers and such using TCP-sockets.
Reply With Quote
  #3  
Old 06-26-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,294
sample using mailx:
Code:
#include <stdlib.h>
#include <string.h>

#define cknull(x) if((x)==NULL) {perror(""); exit(EXIT_FAILURE);}
#define cknltz(x) if((x)<0) {perror(""); exit(EXIT_FAILURE);}
#define LIST_LEN 4

/******************************* 
* email_it() -
*  emails the contents of a file
*  parms 
*	char *filename - file to email
*  	email recipients are in the array email_list[][] 
*   which has to be terminated with a zero-length element
********************************/

void email_it(char *filename)                                           
{                                                                       
	char tmp[256]={0x0};                                                
	char fpBuffer[512]={0x0};                                           
	char email_list[LIST_LEN][256]={  {"username@somecompany.com"},             
							   {"username@somecompany.com"},             
							   {"username@anothercompany.com"},         
							   {0x0}};                                  
	int i=0;                                                            
																		
	for(i=0;*email_list[i]>0x0;i++)                                
	{		                                                            
		cknull(strcpy(tmp, email_list[i]));                             
		cknltz(sprintf (fpBuffer,                                       
			"/usr/bin/mailx -s '%s %s' %s < %s",                        
			"Please Review:",                                           
			filename,                                                   
			tmp,                                                        
			filename)); 	                                            
		if(system (fpBuffer)==(-1))                                     
		{                                                               
			perror("email failure");                                    
			exit(EXIT_FAILURE);	                                        
		}                                                               
	}	                                                                
}
Reply With Quote
  #4  
Old 07-07-2006
Registered User
 

Join Date: May 2006
Posts: 101
you can also use popen() and print the content to the fp
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0