示例#1
0
bool
wxEmail::Send(wxMailMessage& message,
              const wxString& profileName,
              const wxString& sendMail)
{
    wxASSERT_MSG( !message.m_to.IsEmpty(), _T("no recipients to send mail to") ) ;


    // The 'from' field is optionally supplied by the app; it's not needed
    // by MAPI, and on Unix, will be guessed if not supplied.
    wxString from = message.m_from;
    if ( from.empty() )
    {
        from = wxGetEmailAddress();
    }

    wxString msg;
    msg << wxT("To: ");

    const size_t rcptCount = message.m_to.GetCount();
    for (size_t rcpt = 0; rcpt < rcptCount; rcpt++)
    {
        if ( rcpt )
            msg << wxT(", ");
        msg << message.m_to[rcpt];
    }

    msg << wxT("\nFrom: ") << from << wxT("\nSubject: ") << message.m_subject;
    msg << wxT("\n\n") << message.m_body;

    wxString filename;
    filename.Printf(wxT("/tmp/msg-%ld-%ld-%ld.txt"), (long) getpid(), wxGetLocalTime(),
        (long) rand());

    {
        wxFileOutputStream stream(filename);
        if (stream.Ok())
        {
            stream.Write(msg, msg.Length());
        }
        else
        {
            return FALSE ;
        }
    }

    // TODO search for a suitable sendmail if sendMail is empty
    wxString sendmail(sendMail);

    wxString cmd;
    cmd << sendmail << wxT(" < ") << filename;

    // TODO: check return code
    wxSystem(cmd.c_str());

    wxRemoveFile(filename);

    return TRUE;
}
示例#2
0
// Get Full RFC822 style email address
bool wxGetEmailAddress(wxChar *address, int maxSize)
{
    wxString email = wxGetEmailAddress();
    if ( !email )
        return false;

    wxStrlcpy(address, email.t_str(), maxSize);

    return true;
}
示例#3
0
// Get Full RFC822 style email address
bool wxGetEmailAddress(wxChar *address, int maxSize)
{
    wxString email = wxGetEmailAddress();
    if ( !email )
        return false;

    wxStrncpy(address, email, maxSize - 1);
    address[maxSize - 1] = wxT('\0');

    return true;
}
示例#4
0
文件: output.cpp 项目: euler0/Helium
void InteractiveOutputTestCase::TestUserInfo()
{
#ifdef TEST_INFO_FUNCTIONS
    wxPuts(wxT("*** Testing user info functions ***\n"));

    wxPrintf(wxT("User id is:\t%s\n"), wxGetUserId().c_str());
    wxPrintf(wxT("User name is:\t%s\n"), wxGetUserName().c_str());
    wxPrintf(wxT("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
    wxPrintf(wxT("Email address:\t%s\n"), wxGetEmailAddress().c_str());

    wxPuts(wxEmptyString);
#endif // TEST_INFO_FUNCTIONS
}
示例#5
0
文件: email.cpp 项目: AluOne/OpenCPN
bool wxEmail::Send(wxMailMessage& message,  int sendMethod, const wxString& profileName,
    const wxString& sendMail2, const wxString& sendMail1, const wxString& sendMail0)
{
    wxASSERT_MSG( !message.m_to.IsEmpty(), _T("no recipients to send mail to") ) ;

    wxString from = message.m_from;
    if ( from.empty() )
    {
        from = wxGetEmailAddress();
    }

    wxString msg,sendmail;

    if(sendMethod == 0) {                    //with xdg-email via local mail system (MUA)

    if(wxFileExists(sendMail0))
        sendmail << sendMail0;
    else if(wxFileExists(sendMail1))
        sendmail << sendMail1;
    else {
    wxLogMessage(_T("MAIL Error: xdg-email is not installed on this computer!") );
    return false;
    }

    msg << wxT("sh") << wxT(" ") << sendmail << wxT(" --utf8");                     //command
    msg << wxT(" --subject") <<  wxT(" '") << message.m_subject  << wxT("' ");      //subject argument
    msg << wxT("--body") << wxT(" '") << message.m_body << wxT("'");                //body argument

    for (size_t rcpt = 0; rcpt < message.m_to.GetCount(); rcpt++)                   //mail to argument
        msg << wxT(" '") << message.m_to[rcpt] << wxT("'");

    wxSystem(msg.c_str());

    return true;

    } else {                                 //directly with sendmail
        msg << wxT("To: ");
        for (size_t rcpt = 0; rcpt < message.m_to.GetCount(); rcpt++) {
            if ( rcpt ) msg << wxT(", ");
            msg << message.m_to[rcpt];
        }
        msg << wxT("\nFrom: ") << from << wxT("\nSubject: ") << message.m_subject;
        msg << wxT("\n\n") << message.m_body;

        wxString filename;
        filename.Printf(wxT("/tmp/msg-%ld-%ld-%ld.txt"), (long) getpid(), wxGetLocalTime(),
            (long) rand());

        wxFileOutputStream stream(filename);
        if (stream.Ok())
            stream.Write(msg.ToUTF8(), msg.Length());
        else
            return FALSE;

        // TODO search for a suitable sendmail if sendMail is empty
        sendmail << sendMail2;

        wxString cmd;
        cmd << sendmail << wxT(" < ") << filename;

        // TODO: check return code
        wxSystem(cmd.c_str());

        wxRemoveFile(filename);

        return TRUE;
    }
}