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
195 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
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now