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?

BR,
GurcanKAsked:
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.

http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol

A list of the SMTP commands: http://www.cs.cf.ac.uk/Dave/PERL/node175.html

You'll also need to know how to construct MIME headers but, again, this isn't too hard.
http://en.wikipedia.org/wiki/MIME
0

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?
0
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.
0
jkrCommented:
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         "www@example.org"


int mail2admin(char* url, char* link)
{ FILE *pipe, *fp;  
  char *buff, *email;
  int found=0;  if (!url||!link ) return -1;
  buff =(char*)malloc(1024);
  email=(char*)malloc(1024);
  if (!!(fp=fopen(EDITORS,"r")))
  { for (;!found;)
    { if (!fgets(buff,1000,fp)) break;
      if (*buff=='#' ||!strchr(buff,'\t')) continue;
      strcpy(email,strrchr(buff,'\t')+1);
      *strchr(buff,'\t')='\0';;          
      if (strstr(url,buff)) found++;
    }
    fclose(fp);
  }
  sprintf(buff,"%s -f %s %s",MAIL,W3ADMIN,found?email:W3ADMIN);
  pipe=popen(buff,"w");
  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"
          ,getenv("REMOTE_HOST")?getenv("REMOTE_HOST"):""
          ,url);
  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"));
  }
  pclose(pipe);
  free(buff);
  free(email);
  return 0;
}

Open in new window

0
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.