OP here. The code I quoted in my last message (see below) works in a simple
Win32 DLL build with VS2005. I don't know why my original code didn't work
in VS2005.
multiple attachments etc. please just email me (remove "*no-spam*" from the
quoted email address) and I will send it by return. The prototype is as
I'm half way to answering my own question (as no one else has!). I'm
beginning to think this is a VS2005 problem, as I just built a test simple
DLL in VS2003 modelled on the code I quoted below, which uses the
following exported function, WHICH WORKS!
// -----------------------------------------------------
extern "C" _declspec(dllexport) BOOL SendSMTPMessage(LPCTSTR szServer,
LPCTSTR szFrom, LPCTSTR szTo, LPCTSTR szSubject,
LPCTSTR szAttachments, LPCTSTR szBody)
{
CoInitialize(NULL);
{
CMimeMessage msg;
msg.SetSender(szFrom);
//msg.SetSenderName(_T("Peter Boulton"));
msg.AddRecipient(szTo);
msg.SetSubject(szSubject);
msg.AddText(szBody);
if(szAttachments != NULL)
msg.AttachFile(szAttachments);
msg.SetPriority(ATL_MIME_HIGH_PRIORITY);
// Attempt to connect to the specified SMTP server
CSMTPConnection connection;
if (!connection.Connect(szServer))
{
MessageBox(NULL, _T("Unable to connect to server!"), "SMTP.DLL", MB_OK);
return FALSE;
}
else
{
if (!connection.SendMessage(msg))
{
MessageBox(NULL, _T("Connected to server but failed to send message!"),
"SMTP.DLL", MB_OK);
return FALSE;
}
}
}
CoUninitialize();
MessageBox(NULL, "Your email was sent!", "SMTP.DLL", MB_OK);
return TRUE;
}
// -----------------------------------------------------
Over the weekend I shall try to port the DLL to VS2005 and see if it
works!
Incidentally, the original (VS2005) code falls over during one of the
WriteData() calls within CSMTPConnection::SendMessage().
Any feedback welcome, in the meantime! Thanks!
Pete
"Peter Boulton" <peter@data*no-spam*perceptions.co.uk> wrote in message
news:e4srk5$gan$1$8300dec7@news.demon.co.uk...
Hi,
I'm trying to send an email using the following code, but it always fails
to send the message on the "if (!connection.SendMessage"(msg))" line:
#include <atlsmtpconnection.h> // Required for smtp mail!
void SendIt(void)
{
CoInitialize(NULL);
{
CMimeMessage msg;
msg.SetSender(m_From);
msg.SetSenderName(_T("Peter Boulton"));
msg.AddRecipient(m_To);
msg.SetSubject(m_Subject);
msg.AddText(m_Body);
msg.AttachFile(m_Attachment);
msg.SetPriority(ATL_MIME_HIGH_PRIORITY);
// Attempt to connect to the specified SMTP server
CSMTPConnection connection;
if (!connection.Connect(m_Server))
MessageBox(_T("Unable to connect to server!"));
else
{
if (!connection.SendMessage(msg)) // <<<<< Always fails here!
MessageBox(_T("Connected to server but failed to send message!"));
}
}
CoUninitialize();
}
All the variables are correctly initialised and set etc..
Any help greatly appreciated! This is in an MFC dialog application,
built and compiled with VS2005.
Pete