The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
grep unix.com with google



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread 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
  #2 (permalink)  
Old 06-26-2006
Registered User
 

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

Join Date: Feb 2004
Location: NM
Posts: 6,006
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);	                                        
		}                                                               
	}	                                                                
}

  #4 (permalink)  
Old 07-07-2006
Registered User
 

Join Date: May 2006
Posts: 101
you can also use popen() and print the content to the fp
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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 07:56 PM
How to Send email in UNIX cooolthud Shell Programming and Scripting 1 01-23-2007 08:49 AM
Send email where # is in the email address - Using Unix jingi1234 UNIX for Dummies Questions & Answers 1 05-23-2005 12:23 PM
Send email from unix terminal on Mac OS 10.x hypamw UNIX for Dummies Questions & Answers 0 05-04-2005 12:26 AM
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 10:43 AM



All times are GMT -4. The time now is 11:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0