]>
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 wxWindows 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__)
64 bool wxEmail::Send(wxMailMessage
& message
, const wxString
& profileName
, const wxString
& sendMail
)
66 wxASSERT (message
.m_to
.GetCount() > 0) ;
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();
76 wxASSERT (!from
.IsEmpty());
82 for (i
= 0; i
< message
.m_to
.GetCount(); i
++)
84 msg
<< message
.m_to
[i
];
85 if (i
< message
.m_to
.GetCount())
89 msg
<< wxT("\nFrom: ") << from
<< wxT("\nSubject: ") << message
.m_subject
;
90 msg
<< wxT("\n\n") << message
.m_body
;
93 filename
.Printf(wxT("/tmp/msg-%ld-%ld-%ld.txt"), (long) getpid(), wxGetLocalTime(),
97 wxFileOutputStream
stream(filename
);
100 stream
.Write(msg
, msg
.Length());
108 // TODO search for a suitable sendmail if sendMail is empty
109 wxString
sendmail(sendMail
);
112 cmd
<< sendmail
<< wxT(" < ") << filename
;
114 // TODO: check return code
115 wxSystem(cmd
.c_str());
117 wxRemoveFile(filename
);
122 #error Send not yet implemented for this platform.