Solved

send email and attachment from another application written in C,  specifying SMPT server name and sender's email address

Posted on 2001-06-05
3
200 Views
Last Modified: 2008-03-03
What is the easiest way to send emails including attachments from within another application (written in C), specifying the SMPT Server Name and sender's email address (without using the default email client)? Is it possible to get some sample code in C?
0
Comment
Question by:birgitkelly
[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
3 Comments
 
LVL 22

Expert Comment

by:ambience
ID: 6158465
hmmm ... that is a whole lot of work , the easiest way is to use classes that others have built for this purpose or equivalently C code if you find somewhere , there are some good C++ sources on codeguru and codeproject .. I haven't seen any pure C thing as such .. but i guess you can get the idea and do it in C as well.

The other way is to write your own code for talking to SMTP servers , see the RFC on SMTP for more info about the protocol.
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 70 total points
ID: 6158517
Easiest way to send EMail: use tapi
see Simple MAPI Console Application
http://support.microsoft.com/support/kb/articles/q171/0/96.asp
Standart way: use sockets. As examples see
  Send mail with Sockets
  www.xmailserver.com/davide.html

Use JMail component:
  You can use JMail component to send and receive mails.  Its a very cool component and you can download
it free from http:\\dimac.net

See the following code to send mail

#include <windows.h>
#include <stdio.h>
#include <conio.h>

#import "path where you have your jmail.dll is installed \jmail.dll" no_namespace

int main()
{
    CLSID clsid;
    ISMTPMailPtr smtpptr;
   
    if (FAILED(::CoInitialize(NULL))) return 0;
    ::CLSIDFromProgID(L"jmail.SMTPMail",&clsid);
   
    if (FAILED(smtpptr.CreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER)))
    {
         printf("Failed to Create Instance");
         getch();
    }

    smtpptr->ServerPort = 8000;
    smtpptr->ServerAddress = "192.168.20.1";
    smtpptr->AddRecipient(_bstr_t("tparavind@yahoo.com"));
    smtpptr->Subject = "Hai";
    smtpptr->Body = "This is the test mail using Jmail Component";
    smtpptr->SenderName = "Thirumalaiappan";
    smtpptr->Execute();

    return 0;
}
 
I hope, you chouse one of this ways.
Alex
0
 

Author Comment

by:birgitkelly
ID: 6178888
Sorry it took soo long to reply. I have checked out all the links in your email. They were all very good. I have decided to send emails with sockets (http://www.xmailserver.com/davide.html). I have downloaded SndMail 1.8 which works wonderful. It allows for email to be sent from the command prompt or via use of the dll. And best of all, the source code is included. Thank you very much for your help.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

710 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