Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sending an email from a linux c program

Posted on 2003-03-16
7
Medium Priority
?
195 Views
Last Modified: 2010-04-15


  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
Comment
Question by:doveditul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Accepted Solution

by:
foreverfresh earned 100 total points
ID: 8150571
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
 
LVL 8

Expert Comment

by:ssnkumar
ID: 8157225
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
 
LVL 5

Expert Comment

by:Netminder
ID: 8157349
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:doveditul
ID: 8163887


 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
 
LVL 5

Expert Comment

by:Netminder
ID: 8164605
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
 
LVL 20

Expert Comment

by:jmcg
ID: 10143876
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question