]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "email.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/string.h"
28 #include "wx/net/email.h"
31 #include "wx/net/smapi.h"
35 #include "wx/filefn.h"
37 #include "wx/wfstream.h"
43 // Specify profile, or leave it to wxWidgets to find the current user name
46 bool wxEmail::Send(wxMailMessage
& message
, const wxString
& profileName
, const wxString
& WXUNUSED(sendMail
))
48 wxASSERT (message
.m_to
.GetCount() > 0) ;
50 wxString
profile(profileName
);
51 if (profile
.IsEmpty())
52 profile
= wxGetUserName();
54 wxMapiSession session
;
56 if (!session
.MapiInstalled())
58 if (!session
.Logon(profile
))
61 return session
.Send(message
);
63 #elif defined(__UNIX__)
65 wxEmail::Send(wxMailMessage
& message
,
66 const wxString
& profileName
,
67 const wxString
& sendMail
)
69 wxASSERT_MSG( !message
.m_to
.IsEmpty(), _T("no recipients to send mail to") ) ;
72 // The 'from' field is optionally supplied by the app; it's not needed
73 // by MAPI, and on Unix, will be guessed if not supplied.
74 wxString from
= message
.m_from
;
77 from
= wxGetEmailAddress();
83 const size_t rcptCount
= message
.m_to
.GetCount();
84 for (size_t rcpt
= 0; rcpt
< rcptCount
; rcpt
++)
88 msg
<< message
.m_to
[rcpt
];
91 msg
<< wxT("\nFrom: ") << from
<< wxT("\nSubject: ") << message
.m_subject
;
92 msg
<< wxT("\n\n") << message
.m_body
;
95 filename
.Printf(wxT("/tmp/msg-%ld-%ld-%ld.txt"), (long) getpid(), wxGetLocalTime(),
99 wxFileOutputStream
stream(filename
);
102 stream
.Write(msg
, msg
.Length());
110 // TODO search for a suitable sendmail if sendMail is empty
111 wxString
sendmail(sendMail
);
114 cmd
<< sendmail
<< wxT(" < ") << filename
;
116 // TODO: check return code
117 wxSystem(cmd
.c_str());
119 wxRemoveFile(filename
);
124 #error Send not yet implemented for this platform.