• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

Sending an email from a linux c program



  Hy guys !


 Can somebody give me a solution for sending an email from a c program ( a bit of code would be apreciated )

 I'm using Mandrake 9.0 , postfix and a simple pop daemon .

Tanks !!!
0
doveditul
Asked:
doveditul
1 Solution
 
foreverfreshCommented:
hi,
i sent answer for this question
//----------------------------------------------
#include <stdio.h>
#include <stdlib.h>


void my_sendmail(char *mail_from,char *mail_to,char *subject,char *message)
{
  FILE *mail,*htm;
  char sendmail_path[256];
  sprintf(sendmail_path,"/usr/lib/sendmail %s",mail_to);
  mail = popen(sendmail_path,"w");
  fprintf(mail,"Reply-to: %s\n",mail_from);
  fprintf(mail,"From: %s\n",mail_from);
  fprintf(mail,"To: %s\n",mail_to);
  fprintf(mail,"Subject: %s \n",subject);
  fprintf(mail,"MIME-Version: 1.0\n");
  fprintf(mail,"Content-Type: text/html\n\n");
  fprintf(mail,message);
  fprintf(mail,"\r\n");
  pclose(mail);
 }


int main()
    {
      char my_message[1024];
      strcpy(my_message,"Hello,\n this is a test mail\n");
      my_sendmail("mymail@address.com","test@domain.com","Test mail",my_message);
      return(0);
    }

//---------------------------------

or ypu can see all other comments
http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_20410014.html
0
 
ssnkumarCommented:
foreverfresh,
You are violating the EE rules by posting the complete code! He may be doing some homework and you are preventing him from learning by posting the code. You could have asked him if he has written code and could have suggested changes/improvements.

doveditul,
Please don't use the code posted by foreverfresh. You try to learn on your own. RFC-821 discusses protocol for sending mail(Simple Mail Transfer Protocol). You can download it here: www.ietf.org/rfc/rfc821.txt
Study that rfc and learn different commands sent by the mail client. Try to experiment with a mail server by sending the commands.
The following command lets you connect to the mail server for sending mails:
telnet mail-server-ip 25
You have to replace mail-server-ip by the actual ip address of the mail server. After connecting to the server, send different commands and see what happens. Once you got to know all the commands, try to send the same commands over a socket, by using socket programming. If you don't know socket programming, better learn the basic concepts of it and then start.
Revert back, if you find any problem while doing these....

-Narendra
0
 
NetminderCommented:
doveditul,

Is this homework?

foreverfresh,

As noted, it's a violation of EE guidelines to ask that Experts do homework ("academic dishonesty"), but as with the person who takes a bribe, it's a far worse offense to provide it.

So far, I can't find anything to indicate this IS homework (it could be just laziness), but I'd advise erring on the side of caution.

If there is nothing forthcoming from the Asker, this question will be deleted in three days.

Netminder
EE Admin
0
Become a Leader in Data Analytics

Gain the power to turn raw data into better business decisions and outcomes in your industry. Transform your career future by earning your MS in Data Analytics. WGU’s MSDA program curriculum features IT certifications from Oracle and SAS.  

 
doveditulAuthor Commented:


 is not about a home work ,

 And to ssnkumar to conect to a mail server i know belive me.

And i don't know why are you all so mad ??

 My question was , I'm gonna repeat it maybe someone did not read it  :
 
" Can somebody give me a solution for sending an email from a c program ( a bit of code would be apreciated ) "

A specialy mentionated "a bit of code " .

 Any way ... the ideea maybe is that i posted wrong the question , the best was to ask how to open a pipe !!!
 Anyway  sorry for offence to anyone.

10x for answer foreverfresh .


0
 
NetminderCommented:
doveditul,

No one is angry. There's a section of the Membership Agreement that prohibits "academic dishonesty" -- so members are not allowed to do people's homework for them. Your question appeared, to one Expert, to fall into that category, so I asked. Please do not be offended; it's just better to be safe than sorry.

Netminder
EE Admin
0
 
jmcgOwnerCommented:
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by foreverfresh.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now