How to e-mail from C program ?


 
Thread Tools Search this Thread
Top Forums Programming How to e-mail from C program ?
# 1  
Old 11-03-2006
How to e-mail from C program ?

This works fine when typed at the Unix prompt.

echo "This is body" | mail -s "This is subject" "id@domain.com")


But this does not put the Subject Line in the e-mail.

int MainProcess()
{
char cmd[500];
sprintf( cmd, "echo %s | mail -s %s %s\n","This is body","Subject Line","id@domain.com");
if (system ( cmd ) !=0 )
{
fprintf(stderr, "error calling system");
}
return SUCCESS;
}
# 2  
Old 11-03-2006
Code:
sprintf( cmd, "echo '%s' | mail -s '%s' %s\n","This is body","Subject Line","id@domain.com");

You have to force the shell to delimit the body and subject using single quotes
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies

2. UNIX for Dummies Questions & Answers

Short Mail Program Help

Hi, I have been out of the loop with my UNIX/Linux for several years and have been working mainframe. I was trying to create a short two line program to create a list of email addresses as a variable and then send the list a file. Here is what I did and I thought that is was right, but I am... (3 Replies)
Discussion started by: jbrider
3 Replies

3. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

4. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

5. Shell Programming and Scripting

Problem using mailx instead of mail in perl program

I have a perl program that uses the mail program to send emails. It works fine but because I want to change the return address on the emails to be different I need to use mailx with the "-r" option. the problem is when I change this line to use mailx I no longer recieve "any" emails. This works... (1 Reply)
Discussion started by: kieranfoley
1 Replies

6. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

7. Solaris

how to forward mail in /var/mail/username to external mail

Dear All, Now I use solaris 10 and I try to forward mail from /var/mail/username to their external mail so what should I do? thank u in advance (2 Replies)
Discussion started by: unitipon
2 Replies

8. Shell Programming and Scripting

mail program on shell script didn't work, please advise.

Hi, everyone: I post a new thread because previous post may sink and I hope the new one can be caught by your eyes. I created a shell script and the script works fine. However, the mail program part on script didn't send email to my email box and it also didn't provide any traceable... (7 Replies)
Discussion started by: duke0001
7 Replies

9. UNIX for Dummies Questions & Answers

send mail in sh program

Hi, I have a bsh program that needs to send out mail everytime someone runs. How do I send out mail without attach any file? I only need to write one line of message. Thanks for your help! (1 Reply)
Discussion started by: whatisthis
1 Replies

10. UNIX for Dummies Questions & Answers

mail problem (NOT Mail or Mail.app)

When I try to use the CLI mail, I get the following error. What's wrong? Welcome to Darwin! % mail root Subject: test test . EOT % /etc/mail/sendmail.cf: line 81: fileclass: cannot open /etc/mail/local-host-names: Group writable directory Do I just need to change the... (1 Reply)
Discussion started by: chenly
1 Replies
Login or Register to Ask a Question