![]() |
| | #1 |
| Guest
Posts: n/a
| 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. |
| | #2 | |
| &TH of undefined behavior 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 Quote:
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 |
| | #3 |
| and the hat of Jobseeking 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 |
| | #4 |
| Registered User Join Date: Jan 2002
Posts: 9
| 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 |
| | #5 |
| Guest
Posts: n/a
| 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. |
| | #6 |
| Banned 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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |