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 03:56 PM
How to Send email in UNIX cooolthud Shell Programming and Scripting 1 01-23-2007 04: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 06:43 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
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 (permalink)  
Old 06-26-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
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 (permalink)  
Old 06-26-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,502
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 (permalink)  
Old 07-07-2006
Registered User
 

Join Date: May 2006
Posts: 95
you can also use popen() and print the content to the fp
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:42 PM.


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

Content Relevant URLs by vBSEO 3.2.0