Sending mail in C/C++ in unix server

Thread Tools Search this Thread
Top Forums Programming Sending mail in C/C++ in unix server
# 1  
Old 01-02-2008
Sending mail in C/C++ in unix server

Hi Frnds,

I have a task in my project wherein i have to send out a mail from my C++ code.With some file attachements.Please help me in this.

At a higher level wat i can tell is my code generated 3 csv file and i have to send these files as attachement.

My code is executed in unix server.So please suggest me how to do this.

If possible also please tell me how to do this in windows also.

Thanks in advance please reply asap.
# 2  
Old 01-02-2008
Originally Posted by electroon
My code is executed in unix server.
Use fork()/exec()/wait() or system() to run a shell script to wrap the email client.

Originally Posted by electroon
If possible also please tell me how to do this in windows also.
Use MAPI2.
# 3  
Old 01-03-2008
popen() using sendmail directly might be an option to.
# 4  
Old 01-03-2008
Can u elaborate

Can u please tell more details i am somewhat naive user
# 5  
Old 01-03-2008
Originally Posted by electroon
i am somewhat naive user
But you can program in C & C++?

On UNIX, I was suggesting you write a script to wrap the email functionality so this can be customized without recompilation, then call this from the C++ program.

On Windows you should use the MAPI 2 interface, this provides an COM/OLE interface to a mail provider and supports adding attachments as part of the API.
# 6  
Old 01-04-2008
I'm in agreement with the other folks in this thread that
using established systems mail tools to accomplish what you
are doing is simpler.

If you really need to do the entire project in C you could take
a look at libesmtp -- libESMTP - A Library for Posting Electronic Mail
Or possibly the c-client library bundled with UW imap: UW IMAP software--IMAP Information Center.
# 7  
Old 01-21-2008

Originally Posted by electroon
Can u please tell more details i am somewhat naive user
popen is a very simple function to use. It allows you to open a system command as a FILE stream, for reading or writing. To send an email, you will want to open a stream for writing so you can "print" the contents of the email into the function:

FILE *mailer = popen("/usr/bin/mail -s 'Some subject here' user@domain", "w");
fprintf(mailer, "Hello %s,\nThis note is to inform you that your job completed successfully.\n", username);
You would, of course, want to add some error checking to this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issues sending emails using PostFix Mail Server

I'm unable to send email from my Linux server despite SMTP port 25 Active and Listening. # hostname TechX I checked the mail log ( /var/log/maillog ) and found the below error. I'm sharing all the ".cf" files seen in the error log. 1. # more /etc/postfix/ # postfix... (0 Replies)
Discussion started by: mohtashims
0 Replies

2. UNIX for Dummies Questions & Answers

Sending e-mail from unix

Hello, I want to send an email from unix. I tried following commands: mailx -s "hello" < echo_manish and echo "Testing Mail" | mailx -s "hello" but in both the commands nothing is happening. I mean it is neither giving any error nor I am receiving... (7 Replies)
Discussion started by: manishdivs
7 Replies

3. Shell Programming and Scripting

php code - Sending mail with external SMTP server

Here is the code: <?php //new function function loadini($path) { $fp = fopen($path, "r"); $fpcontents = fread($fp, filesize($path)); fclose($fp); return $fpcontents; } $to = ""; $nameto = "notme"; $from = "test"; $namefrom = "Who From"; ... (0 Replies)
Discussion started by: galford
0 Replies

4. HP-UX

[Solved] How do I configure Unix Mail Server to use another Mail Exchange Server

We have configured our mail unix server and can send out emails automatically from applications running on unix to different people in our company as well as outside our company. However there is an outside client who is not receiving these emails because the settings on their mail server cannot... (4 Replies)
Discussion started by: Tenyhwa
4 Replies

5. Programming

Mail sending from VFP9 through internal postfix esmtp server.

hi all, please help me in this regard. I am VFP 9 programmer. I want to send the mail from within VFP 9 application. I have used CDO of microsoft which is working fine. however to be able to send the mail i have to setup the router gateway on user machine which enable him to surf through the... (0 Replies)
Discussion started by: choudharidl
0 Replies

6. Linux

help sending mail on linux server

Hi, I coded a bash script.I m trying to use this command in the script mail -s "test" I tried this command on prompt.however it hangs.I check /var/log/maillog/ stat=Deferred: Connection timed out with sendmail: n0M8lscO014303: localhost did not issue... (2 Replies)
Discussion started by: sunsail
2 Replies

7. UNIX for Dummies Questions & Answers

sending mail from unix

Hi, I am using mailx command to send mail through Unix. But I am able to send mail only within my domain. If i want to send mail to some other server, it's not working. Like say If I want to send mail to someone on gmail or yahoo it's not working. but it's working fine within my company domain.... (3 Replies)
Discussion started by: anki_1
3 Replies

8. UNIX for Advanced & Expert Users

sending email via mail server

hi everyone i am facing one problem. there is one unix server in our organisation which stores daily routine backup, and one mail server which is on windows 2k3, they are on one intranet. now i want that a mail should be generated and sent to the e-mail id of employees like (1 Reply)
Discussion started by: parmeet
1 Replies

9. HP-UX

Sending msg From Unix Server to an E-mail Address

Dear Brothers in Unix I would like to change some HP-UX settings in order that the system send a message to root it should be copied to my e-mail address in Microsoft Exchange Server. Please can you help me. Best Regards and thanks in advance Gege (2 Replies)
Discussion started by: cgege
2 Replies

10. UNIX for Dummies Questions & Answers

block certain domain from sending mail to server

hi currently i have a server that is able to send out and receive mail. is there a way to configure the server such that mails can be sent to a certain domail like but block mails from this domain the server is running on solaris 10. thanks in advance :) (2 Replies)
Discussion started by: legato
2 Replies
Login or Register to Ask a Question