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.
Bundy
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Apr 29, 2005 9:46 am
Location: Poland

How to send email from wxWidget Application?

Post by Bundy » Wed Aug 31, 2005 7:07 am

Hej all, I was searching topics for method to send email using wxWidgets but I didn't find it. I have wxString with content of email, I have email address where I want to send my email and address of my post server SMTP and POP3. Meybe somebody knows how to send this email from wxWidgets?

Thanks
Bundy
"Fate rewards prepared mind"

Quote from movie "Liberator 2"

User avatar
kolo
Earned some good credits
Earned some good credits
Posts: 120
Joined: Tue Jun 21, 2005 1:19 pm
Location: Russia, Cheboksary
Contact:

Post by kolo » Wed Aug 31, 2005 7:38 am

2 or 3 days ago there was topic about sending e-mail, use search :)
only MSW & MSVS ))

benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte » Wed Aug 31, 2005 7:43 am

In the "Utilities and libraries supplied with wxWidgets" topic of the wxWidgets help, there is a paragraph about "Net library":
Net is a collection of very simple mail and web related classes. Currently there is only wxEmail, which makes it easy to send email messages via MAPI on Windows or sendmail on Unix. You can find this in contrib/src/net and contrib/include/wx/net.
It may be able to send emails with contents, while the previous message was just a question about "mailto:..."

Bundy
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Apr 29, 2005 9:46 am
Location: Poland

Post by Bundy » Wed Aug 31, 2005 8:55 am

I did simple frame with button and function:

Code: Select all

void Projekt1Frm::WxButton1Click(wxCommandEvent& event)
{
	// insert your code here
	wxMailMessage content("subject", "[email protected]","body", "from");
	wxEmail *mail = new wxEmail();
	wxString profile;
	wxString last_param;
	bool retval = mail->Send(content,profile,last_param);
	if(retval)
             wxLogMessage("ok");
    else
             wxLogMessage("faild");              
	event.Skip();
}
I have no compiler errors but Send return false
"Fate rewards prepared mind"

Quote from movie "Liberator 2"

benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte » Wed Aug 31, 2005 9:03 am

What does happen when you step into ::Send() :?:

Bundy
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Apr 29, 2005 9:46 am
Location: Poland

Post by Bundy » Wed Aug 31, 2005 9:12 am

Send is a method of class wxEmail:

Code: Select all

bool wxEmail::Send(wxMailMessage& message, const wxString& profileName, const wxString& WXUNUSED(sendMail))
{
    wxASSERT (message.m_to.GetCount() > 0) ;

    wxString profile(profileName);
    if (profile.IsEmpty())
        profile = wxGetUserName();

    wxMapiSession session;

    if (!session.MapiInstalled())
        return FALSE;
    if (!session.Logon(profile))
        return FALSE;

    return session.Send(message);
}
this is in folder contrib/src/wx/net in file email.cpp

p.s.

3 days ago was post and autor wrote how to open Outlook Express and put address in address field:

Code: Select all

    wxString sendTo = "mailto:"; 
    sendTo += "[email protected]"; 

    ShellExecute(NULL,"open", sendTo.c_str(), "", "", 0);    
but I need solution for windows without outlook express, my application has to send email - not open another to do this
"Fate rewards prepared mind"

Quote from movie "Liberator 2"

benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte » Wed Aug 31, 2005 9:23 am

Thanks, I know where the method Send is and what it contains.

I asked you to step into and to see why you get a FALSE. You may understand something by doing that. There are 3 reasons why you get a FALSE. Find which one and you will almost have found what's wrong.

I don't use this class in my applications.

Bundy
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Apr 29, 2005 9:46 am
Location: Poland

Post by Bundy » Wed Aug 31, 2005 9:52 am

Ups, wxEmail send mail using Outlook Express to.

p.s. It starts working when I add all files to my project.
"Fate rewards prepared mind"

Quote from movie "Liberator 2"

Bundy
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Apr 29, 2005 9:46 am
Location: Poland

Post by Bundy » Thu Sep 01, 2005 7:17 am

In topic http://forums.wxwidgets.org/viewtopic.p ... light=smtp hgiritzer wrote something about wxSMPT class. Does anybody know where I could find this class?
"Fate rewards prepared mind"

Quote from movie "Liberator 2"

priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia » Thu Sep 01, 2005 7:42 am


NinjaNL
Moderator
Moderator
Posts: 899
Joined: Sun Oct 03, 2004 10:33 am
Location: Oosterwolde, Netherlands

Post by NinjaNL » Thu Sep 01, 2005 10:20 am

Bundy wrote:In topic http://forums.wxwidgets.org/viewtopic.p ... light=smtp hgiritzer wrote something about wxSMPT class. Does anybody know where I could find this class?
here
Follow the development of my screenplay authoring program at http://wxscreenplaywriter.blogspot.com/

Bundy
I live to help wx-kind
I live to help wx-kind
Posts: 153
Joined: Fri Apr 29, 2005 9:46 am
Location: Poland

Post by Bundy » Thu Sep 01, 2005 1:52 pm

Ok, first I use complet application which is on page that I have link to from priyank_bolia. Application works (no errors) but I don't receive email on my mailbox.

Second, I use classes that I have link from NinjaNL to, I create my application (very simple), use example on page from NinjaNL:

Code: Select all

    wxSMTP *smtp = new wxSMTP(NULL);
    smtp->SetHost("kos.man.koszalin.pl");
    wxEmailMessage *msg = new wxEmailMessage("Bug report",
                                             "Your code really sucks.\n"
                                             "Fix your code",
                                             "[email protected]");
    msg->AddAlternative("<html><body><h1>Bug report</h1>\n"
                        "Your code <b>really</b> sucks <p>Fix your code</html>",
                        "text","html");
    msg->AddTo("[email protected]");
    smtp->Send(msg);
and still nothing.

I'm thinking that meybe it is error in connection to my SMTP serwer - I think that he wants password, but any of this smtp classes take such parameter. So, have You address of SMTP server that don't needs password?

Thanks for help
"Fate rewards prepared mind"

Quote from movie "Liberator 2"

priyank_bolia
wxWorld Domination!
wxWorld Domination!
Posts: 1339
Joined: Wed Aug 03, 2005 8:10 am
Location: BANGALORE, INDIA
Contact:

Post by priyank_bolia » Thu Sep 01, 2005 2:04 pm

Smtp servers generally don't need passwords, isn't is directly send mails to the smtp server. I guess the validation of your email address by the smtp server can also be a problem.

cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post by cg » Thu Sep 01, 2005 2:15 pm

Hi,

I tried unsuccessully to use wxSmtp classes. I can't remember what the problems were but there were many. I looked at other non-gpl smtp projects out there and non of them were any good and were missing key features. I ended up writing my own client. I found specs at: http://www.faqs.org/rfcs/rfc821.html. It was not that hard since its a simple protocol, the only thing that took some time was making file attachments.

HTH

Chris

------------------------------------------------------------
Chinook Developer Studio
*Free multiplatform IDE for BSD.Linux.Solaris.Windows*
http://www.degarrah.com/chinookfree.php

Zephyr Automated Test Runner
*Cross platform automated functional and regression testing*
http://www.degarrah.com/zephyr.php
------------------------------------------------------------

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

Post by ghostd0g » Mon Apr 10, 2006 1:19 pm

cg wrote:Hi,

I tried unsuccessully to use wxSmtp classes. I can't remember what the problems were but there were many. I looked at other non-gpl smtp projects out there and non of them were any good and were missing key features. I ended up writing my own client. I found specs at: http://www.faqs.org/rfcs/rfc821.html. It was not that hard since its a simple protocol, the only thing that took some time was making file attachments.

HTH

Chris

hi chris,
and would you mind to share your piece of code?
wxSMTP would be exactly what i need but it does not work. it might be the problem of the mailserver but i can't track it right now since there is not really an error handling ...
no i'd like to try it with the same settings with some other libs (wxEmail, ATL, ...)

TIA
ghostd0g

Post Reply