LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-18-2006, 11:42 PM   #1
minhsangniit
LQ Newbie
 
Registered: Mar 2006
Posts: 7

Rep: Reputation: 0
How to use "mail" program from System() call in C?


Hello everybody,

I have a problem to use "mail" program for my code C to send email.

#include <stdio.h>

int main()
{
char cmd[80];
int icount = 0;
int i = 0;


for (i = 0; i < 10; i++)
{
sprintf(cmd, "mail -s \"This a test message%d\" minhsangtech@gmail.com);//<- HOW TO PASS MESSAGE BODY IN IT?
if (system(cmd) == -1)
{
printf("Cannot send email\n");
}
}

return -1;
}
 
Old 08-18-2006, 11:58 PM   #2
kstan
Member
 
Registered: Sep 2004
Location: Malaysia, Johor
Distribution: Dual boot MacOS X/Ubuntu 9.10
Posts: 851

Rep: Reputation: 31
u may put the required string into a text file, just like
"echo this it the text > msgbody"
then something like this (I'd ) mail user < msgbody.

example of the code maybe (I'm not really sure it works)

#include <stdio.h>

int main()
{
char cmd[80];
int icount = 0;
int i = 0;


for (i = 0; i < 10; i++)
{
system("echo this is msgbody > msgbody");
sprintf(cmd, "mail -s \"This a test message%d\" minhsangtech@gmail.com < msgbody");//<- HOW TO PASS MESSAGE BODY IN IT?
if (system(cmd) == -1)
{
printf("Cannot send email\n");
}
}

return -1;
}

hope this help u.
 
Old 08-19-2006, 12:08 AM   #3
minhsangniit
LQ Newbie
 
Registered: Mar 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Talking

Quote:
Originally Posted by kstan
u may put the required string into a text file, just like
"echo this it the text > msgbody"
then something like this (I'd ) mail user < msgbody.

example of the code maybe (I'm not really sure it works)

#include <stdio.h>

int main()
{
char cmd[80];
int icount = 0;
int i = 0;


for (i = 0; i < 10; i++)
{
system("echo this is msgbody > msgbody");
sprintf(cmd, "mail -s \"This a test message%d\" minhsangtech@gmail.com < msgbody");//<- HOW TO PASS MESSAGE BODY IN IT?
if (system(cmd) == -1)
{
printf("Cannot send email\n");
}
}

return -1;
}

hope this help u.
Thanks! It worked!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any way to get "Alice"; "Call of Duty" series and "Descent 3" to work? JBailey742 Linux - Games 13 06-23-2006 01:34 PM
C -communicating with system("ftp"); using "program|ftp>>myfifo" probably hansschmucker Programming 1 03-23-2005 01:39 PM
"Function not implemented" error in call to "sem_open()" Krishnendu8 Linux - Newbie 1 06-07-2003 02:52 AM
"Function not imlemented" error in call to "sem_open()" Krishnendu8 Linux - Networking 0 06-07-2003 02:19 AM
Using the "system( )" system call causes exit sometimes AbhiShek Linux - Software 6 10-01-2002 02:56 PM


All times are GMT -5. The time now is 03:19 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration