Sending E-Mail in HP-UX using C++

Dear experts,

I would like to write a C++ program in HP-UX to send e-mails to outside. How can I write such a program without using a third party tool or library and just using the supplied default environment?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

evilrixSenior Software Engineer (Avast)Commented:
If you're prepared to learn to communicate with an SMTP server and talk SMTP you can do this by just writing a sockets program that connects directly to the MTA and talks SMTP with it. The SMTP protocol is pretty simple and easy to learn and code.

A list of the SMTP commands:

You'll also need to know how to construct MIME headers but, again, this isn't too hard.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GurcanKAuthor Commented:
Hi, that's good feedback. However, I need some code example. Could you please provide some?
evilrixSenior Software Engineer (Avast)Commented:
>> However, I need some code example. Could you please provide some?
I don't have any to hand -- if I get a chance later I'll try and knock up a quick example for you.
If you don't want to go down to the SMTP protocol level, sending a mail by shelling out 'sendmail' is quite handy also. The following snippet does exactly that (originally written to automatically notify webmasters of dead links):
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>

   gcc  -Wall -pedantic -pipe -O5 -o err404 err404.c; strip err404

#define MAIL            "/path/to/sendmail"        
#define EDITORS         "/path/to/notfound.editors"

#define W3ADMIN         ""

int mail2admin(char* url, char* link)
{ FILE *pipe, *fp;  
  char *buff, *email;
  int found=0;  if (!url||!link ) return -1;
  buff =(char*)malloc(1024);
  if (!!(fp=fopen(EDITORS,"r")))
  { for (;!found;)
    { if (!fgets(buff,1000,fp)) break;
      if (*buff=='#' ||!strchr(buff,'\t')) continue;
      if (strstr(url,buff)) found++;
  sprintf(buff,"%s -f %s %s",MAIL,W3ADMIN,found?email:W3ADMIN);
  fprintf(pipe,"Subject: Missing link  ;-))\n");
  fprintf(pipe,"Reply-to: %s\n",W3ADMIN);
  fprintf(pipe,"Full-name: Web-Server\n\n");
  fprintf(pipe,"Hello,\n\nHost *%s* has just accessed\n%s\n\n"
  fprintf(pipe,"where an image is referenced ");
  fprintf(pipe,"%s that das not exist.\n",link);
  fprintf(pipe,"\n\nRegards,\n\nYour Server.\n\n");
  if (getenv("HTTP_USER_AGENT"))
  { fprintf(pipe,"PS. Browser: %s",getenv("HTTP_USER_AGENT"));
  return 0;

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.