Can we send email with C program on Unix?


 
Thread Tools Search this Thread
Top Forums Programming Can we send email with C program on Unix?
# 1  
Old 06-26-2006
Power 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  
Old 06-26-2006
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  
Old 06-26-2006
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  
Old 07-07-2006
you can also use popen() and print the content to the fp
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send an email if "No such file or directory" in the shell script program log in EBS concur

Hi All, I have the below code(.sh) and need to send an email. #!/bin/bash cp /u02/xxc_incoming/TEST*.dat /u02/xxc_archive_incoming/AMER7764_ARPP_2/ cat /u02/xxc_incoming/TEST*.dat > /u02/xxc_incoming/XXC_TEST.dat rm /u02/xxc_incoming/TEST*.dat cd $XXC_TOP/bin sqlldr userid=apps/<pwd> ... (12 Replies)
Discussion started by: Mist123
12 Replies

2. Shell Programming and Scripting

send email from unix server

HI Guys, I want send email from my script ..and i have tried below command still no luck. ( uuencode $Adm "Test.txt" ) | mailx -s "Test" P***.P****@at***.com mailx -s "test mail" P****.P***@at***.com < $Admin Any other option.... (2 Replies)
Discussion started by: asavaliya
2 Replies

3. Shell Programming and Scripting

send email issue in unix

Hi, I am trying to send the contents of a file as email in unix.I am using the below code to do this.But when i get the email i see that SUBJECT and TO is blank. Can you please let me know why it is blank? Also the FROM address comes as admin@myhost. Is there any way i can set FROM to user... (5 Replies)
Discussion started by: vignesh53
5 Replies

4. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

5. UNIX for Dummies Questions & Answers

How to send email from HP Unix box

Hi everyone, I am new to HP/UX and I would like to know if there is a way to receive system alerts and logs via email on daily bases. Recently our system crashed due to Hard Disk failure, and since then we are checking ELM every day. I would like to automate that process and have UNIX mail send... (3 Replies)
Discussion started by: eurouno
3 Replies

6. UNIX for Advanced & Expert Users

How to know whether I am able to send email from unix server or not?

How to know whether I am able to send email from unix server or not? I ma trying to send mail to my gmail id using command sendmail -s "Subject" abc@gmail.com Hi How are you? . It showed that You are not allowed to send mail. My question is there any file which contains the list of... (0 Replies)
Discussion started by: siba.s.nayak
0 Replies

7. Shell Programming and Scripting

send email from unix with attachment

Hello All, This is a common question that I found lot of results in the forums. I am trying to use uuencode to attach a file and send email. I have no issues sending email, but not able to attach any files using sendmail. Is uuencode part of sendmail or does 'uuencode' utility need to be... (1 Reply)
Discussion started by: chiru_h
1 Replies

8. Shell Programming and Scripting

How to Send email in UNIX

Hi, I am new to Shell script programming. Can anyone explain How to Send Mail in UNIX. Can explain in detail please? Thanks in Advance. From Sathish D V. (1 Reply)
Discussion started by: cooolthud
1 Replies

9. UNIX for Dummies Questions & Answers

Send email where # is in the email address - Using Unix

Hi All, How do I send an email using malix where email address contains a #. I have a email address like this : #test@test.com I want to send email like malix -s "TEST" #test@test.com < SOMEFILE I tried \# but doesn't work. Please let me know how we can achieve this? I am in... (1 Reply)
Discussion started by: jingi1234
1 Replies

10. UNIX for Advanced & Expert Users

Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win)

Hi A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as " usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)
Discussion started by: Vetrivela
2 Replies
Login or Register to Ask a Question