How to send email from wxWidget Application?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
ashish
Earned a small fee
Earned a small fee
Posts: 14
Joined: Thu May 26, 2005 4:15 pm

Post by ashish »

Take a look at the source code for wino.

http://www.frank-buss.de/wxwindows/wino.html

wxsmtp worked for me after i created a dialog that derives from
public wxSMTPListener to handle setting the parameters and sending the email.

-ashish
ghostd0g
Experienced Solver
Experienced Solver
Posts: 58
Joined: Wed Oct 19, 2005 3:58 pm

Post by ghostd0g »

hmm, could it be, that the default wxSMTPListener (g_nullListener) indeed does nothing?
i thought it was only for reacting on events and not for actually sending it.
and i've read nothing about having to implement a concrete listener for the whole thing to work ...

btw, which version of wxSMTP are you using? v1.11 or v1.12?

wxEmail (IMAPI) works fine, but i do not want to pop-up the mailclient-message-window.
so i tried my own version with ATL which works fine too. but if i can choose i'd like to keep ATL out of my project ...

Code: Select all

#include <atlbase.h>
#include <atlcom.h>
#include <atlmime.h>
#include <atlsmtpconnection.h>

...

::CoInitialize(NULL);

std::string filename("somepath/somefile.jpg");
std::string recipient("[email protected]");

CMimeMessage msg;
msg.SetSender("[email protected]");
msg.SetSenderName("me");
msg.AddRecipient(recipient.c_str());
msg.AttachFile(filename.c_str());

std::string subject("subject line");
std::string text("nice text");

msg.SetSubject(subject.c_str());
msg.AddText(text.c_str());

CSMTPConnection conn;
if (conn.Connect("smtp.somedomain.com"))
{
    bool success = conn.SendMessage(msg);
    conn.Disconnect();    
}

::CoUninitialize();
ashish
Earned a small fee
Earned a small fee
Posts: 14
Joined: Thu May 26, 2005 4:15 pm

Post by ashish »

I am using v 1.11

I am not sure why the listener is needed either, but when I tried to send email without creating the dialog box, I kept geting errors on Connecting the socket.

I am using the email function to send myself a log file and a settings file.
I can post my class here if anyone wants to take a look, but it is basically a small modification of the dialog used in the Wino program.

BTW. I found a bug in:
void wxMimePart::Encode(wxOutputStream& out)

wxUint8* pData = new wxUint8[len]; //is allocated but never deleted.

if you add "delete [] pData;" as shown below:

out.Write((const char*) result.GetData(), result.Length());
delete [] pData; // <---- Insert this

it takes care of it.

-ashish
ghostd0g
Experienced Solver
Experienced Solver
Posts: 58
Joined: Wed Oct 19, 2005 3:58 pm

Post by ghostd0g »

ashish wrote:I am using v 1.11

I am not sure why the listener is needed either, but when I tried to send email without creating the dialog box, I kept geting errors on Connecting the socket.

I am using the email function to send myself a log file and a settings file.
I can post my class here if anyone wants to take a look, but it is basically a small modification of the dialog used in the Wino program.

BTW. I found a bug in:
void wxMimePart::Encode(wxOutputStream& out)

wxUint8* pData = new wxUint8[len]; //is allocated but never deleted.

if you add "delete [] pData;" as shown below:

out.Write((const char*) result.GetData(), result.Length());
delete [] pData; // <---- Insert this

it takes care of it.

-ashish
could you please post your class. so i could test it with my project. maybe i do need a concrete listener.
thx ashish for pointing out that leak. i think i should further investigate that code.
Post Reply