]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/net/email.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxEmail: portable email client class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/string.h"
24 #include "wx/net/email.h"
27 #include "wx/net/smapi.h"
31 #include "wx/filefn.h"
33 #include "wx/wfstream.h"
39 // Specify profile, or leave it to wxWidgets to find the current user name
42 bool wxEmail::Send(wxMailMessage
& message
, const wxString
& profileName
, const wxString
& WXUNUSED(sendMail
))
44 wxASSERT (message
.m_to
.GetCount() > 0) ;
46 wxString
profile(profileName
);
47 if (profile
.IsEmpty())
48 profile
= wxGetUserName();
50 wxMapiSession session
;
52 if (!session
.MapiInstalled())
54 if (!session
.Logon(profile
))
57 return session
.Send(message
);
59 #elif defined(__UNIX__)
61 wxEmail::Send(wxMailMessage
& message
,
62 const wxString
& profileName
,
63 const wxString
& sendMail
)
65 wxASSERT_MSG( !message
.m_to
.IsEmpty(), _T("no recipients to send mail to") ) ;
68 // The 'from' field is optionally supplied by the app; it's not needed
69 // by MAPI, and on Unix, will be guessed if not supplied.
70 wxString from
= message
.m_from
;
73 from
= wxGetEmailAddress();
79 const size_t rcptCount
= message
.m_to
.GetCount();
80 for (size_t rcpt
= 0; rcpt
< rcptCount
; rcpt
++)
84 msg
<< message
.m_to
[rcpt
];
87 msg
<< wxT("\nFrom: ") << from
<< wxT("\nSubject: ") << message
.m_subject
;
88 msg
<< wxT("\n\n") << message
.m_body
;
91 filename
.Printf(wxT("/tmp/msg-%ld-%ld-%ld.txt"), (long) getpid(), wxGetLocalTime(),
95 wxFileOutputStream
stream(filename
);
98 stream
.Write(msg
, msg
.Length());
106 // TODO search for a suitable sendmail if sendMail is empty
107 wxString
sendmail(sendMail
);
110 cmd
<< sendmail
<< wxT(" < ") << filename
;
112 // TODO: check return code
113 wxSystem(cmd
.c_str());
115 wxRemoveFile(filename
);
120 #error Send not yet implemented for this platform.