C Board  

Go Back   C Board > General Programming Boards > C Programming

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 01-11-2002, 04:40 AM   #1
Unregistered
Guest
 
Posts: n/a
Unhappy need some help on email sending in C programming

Hey

itslike this, we're working on this project a evaluation program for students and teachers to evaluate done courses etc, and one of the demands was that the program would send a mail to the teacher running the course when 90% of the registered students had done a evaluation, thing is I cant find anything on how to send a mail through C-code, I've tried custom System(" ") commands with pine and sendmail, but none will work, sendmail requiers root, and that means entering a password etc, pine requires you to type a msg every time, also tried "sudo" commando, and still requires you to enter a password. I really need your help and I would really appreciate it.

A guy in need of help.

ps ..

We're running linux red hat.
 
Old 01-11-2002, 04:52 AM   #2
&TH of undefined behavior
 
Fordy's Avatar
 
Join Date: Aug 2001
Posts: 5,219
I dont do Linux coding, but..........you need to learn how to work with sockets

Then a quick & dirty method;


Connect to your SMTP server on port 25 .....(server could be mail.myserver.com)

send the following strings and end each with '\r\n'..

Code:
HELO mail.myserver.com

MAIL FROM:<your email address>

RCPT TO:<reciever's email address>

DATA

FROM:Your name

TO:reciever's name

SUBJECT:Whatever

Blah blah blah 
Then send '\r\n' twice and send;

Quote:
QUIT
Substitute the italic parts for info specific to the email...

This is off the top of my head, so I havent tested it.....try it on Telnet and substitute each '\r\n' for the ENTER key
__________________
"If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut."
Albert Einstein (1879 - 1955)


Board Rules
Fordy is offline  
Old 01-11-2002, 10:28 AM   #3
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,699
What about 'mail', 'Mail' or 'mailx' via a system("") call?

I seem to remember something like this...
system( "mail -s subject user@host < message.txt" );

I would be mildly surprised if say pine did not have a non-interactive mode - getting programs to send email is a fairly common thing.
Salem is offline  
Old 01-11-2002, 12:27 PM   #4
Registered User
 
Join Date: Jan 2002
Posts: 9
Cool Using sendmail from C

Don't mess with sockets and crap! It's really a very simple problem.

Sendmail doesn't require root, of course it doesn't since the mail system and each user calls it! I use sendmail from my C programs all the time.

Find out where sendmail is on your system.
Typically /usr/lib/sendmail but sometimes /usr/bin/sendmail or /usr/sbin/sendmail (sometimes it's linked from one to the other so it doesn't matter).

To avoid dangerous security situations where an argument from a user (passed from a web page for example) includes escape sequences that can execute arbitrary commands (a BAD THING) don't pass any user arguments to sendmail. Instead, call sendmail with the -t option, this means you will have the recipient specified in the file. So, write a temp file with the email header and body in it, and then pass it to sendmail.

The temp message file should look like this:

To: someguy@someserver.com
From: myreturn@address.com
Subject: This is my email program

This is the message body blah blah blah


NOTE: The temp message file includes the actual MIME headers that sendmail expects, so it's important that they are written in the file just like that -- Initial capital letter, space, colon, etc. Also, the blank line after the Subject: is very important -- the blank line signals the end
of the MIME header and the beginning of the body.

Once your program has generated the temp file, use a system call to sendmail to push it out the door:

system( "/usr/lib/sendmail -t < mytempfile.txt" );

Note the "less than" sign means for sendmail to
read its input from that file.

For the system() call, make sure you #include <stdlib.h>

Thats it -- let me know if it works out for you.

Walter
PopRox is offline  
Old 01-12-2002, 07:51 AM   #5
Unregistered
Guest
 
Posts: n/a
Lightbulb Mail in C code

To Walter:

Tnx for the help, it works ! I dunno how many hours I've spent trying to find a solution that would work. thanks all you guy who helped me out on this one.
 
Old 01-13-2002, 04:36 AM   #6
Banned
 
zahid's Avatar
 
Join Date: Aug 2001
Posts: 532
Fordy, can you tell little more about your way of doing that?
Any reference doc from we.. and sample code.. will be helpfull.

How / where to put your given code?
zahid is offline  
Closed Thread

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C code for Sending Email with attachment Mr coder C Programming 5 03-06-2009 08:15 AM
Spam Filters. ISP based email is dying. Mario F. General Discussions 14 03-05-2008 12:05 PM
Sending Email via C++? Monte C++ Programming 0 07-30-2002 01:14 PM
sending strings from program to email Unregistered C++ Programming 3 04-09-2002 06:23 PM
sending email from (C++)exe file through ASP priya C++ Programming 0 01-18-2002 10:14 AM


All times are GMT -6. The time now is 02:12 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22