Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
210 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 280 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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

971 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