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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create string splitting user defined function in C++ 23 291
Create a path if not exists 7 69
object oriented programming comparison 5 56
c++, dynamic object by json 1 25
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

867 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

23 Experts available now in Live!

Get 1:1 Help Now