Archived Forum Post

Index of archived forum posts

Question:

Progress monitoring for sending emails with attachments?

Jul 20 '17 at 04:19

Is it possible to support some kind of progress monitoring when creating an email, attaching the file and then sending it and closing the connection?

OK, I have located this in the documentation for an event ProgressInfo. How do I go about using these call backs please? I am using the Unicode library with Visual C++ MFC Visual Studio 2017.

Thanks in advance.

Update

I found some useful resources on this subject:

http://www.chilkatforum.com/questions/3387/event-callbacks-in-the-chilkat-c-api

http://cknotes.com/tag/abort/

http://www.chilkatforum.com/questions/3387/event-callbacks-in-the-chilkat-c-api

So I created a new class:

#pragma once
#include "stdafx.h"
#include <CkMailManProgressW.h>

class MyMailProgress : public CkMailManProgressW
{
public:
    MyMailProgress(CWnd *pWnd) : m_pWnd(pWnd)
        , m_strOriginalWindowTitle(_T(""))
    {
        m_pWnd->GetWindowText(m_strOriginalWindowTitle);
    }

    virtual ~MyMailProgress(void) { }

    // Override the AbortCheck method (which is a virtual method in CkMailProgress)
    // Called periodically according to the value of the HeartbeatMs property.
    virtual void AbortCheck(bool *abort) override
    {
        CString strNewTitle = m_strOriginalWindowTitle + _T(" [AbortCheck!]");
        //m_pWnd->SetWindowText(strNewTitle);
        ::OutputDebugString(_T("AbortCheck!"));

        // If your application wishes to abort the email sending/receiving operation,
        // set the abort boolean like this:
        *abort = true;
    }

    // Percentage completion events may also be overridden to abort time-consuming operations.
    void SendPercentDone(long pctDone, bool *abort)
    {
        CString strPercentDone = _T("");
        strPercentDone.Format(_T("SendPercentDone: %d percent"), pctDone);
        //CString strNewTitle = m_strOriginalWindowTitle + strPercentDone;

        //m_pWnd->SetWindowText(strNewTitle);
        ::OutputDebugString(strPercentDone);
    }

    void ReadPercentDone(long pctDone, bool *abort)
    {
        CString strPercentDone = _T("");
        strPercentDone.Format(_T("ReadPercentDone: %d percent"), pctDone);
        //CString strNewTitle = m_strOriginalWindowTitle + strPercentDone;

        //m_pWnd->SetWindowText(strNewTitle);
        ::OutputDebugString(strPercentDone);
    }

    virtual void ProgressInfo(const wchar_t *name, const wchar_t *value) override
    {
        CString strProgress = _T("");
        strProgress.Format(_T("ProgressInfo: %s, %s"), name, value);
        //CString strNewTitle = m_strOriginalWindowTitle + strProgress;

        //m_pWnd->SetWindowText(strNewTitle);
        ::OutputDebugString(strProgress);
    }

private:
    CWnd* m_pWnd;
    CString m_strOriginalWindowTitle;
};

It does work. When I use the OutputDebugString calls:

ProgressInfo: SocketConnect, smtp.live.com:587ProgressInfo: HostnameResolve, smtp.live.com'Meeting Schedule Assistant.exe' (Win32): Loaded 'C:\Windows\System32\mswsock.dll'. Cannot find or open the PDB file.
ProgressInfo: SocketConnected, smtp.live.com:587ProgressInfo: SmtpCmdResp, 220 BLU437-SMTP24.smtp.hotmail.com Microsoft ESMTP MAIL Service, Version: 8.0.9200.16384 ready at  Wed, 19 Jul 2017 14:16:58 -0700 
ProgressInfo: SmtpCmdSent, EHLO DESKTOP-4OHL3UQ<CRLF>
ProgressInfo: SmtpCmdResp, 250-BLU437-SMTP24.smtp.hotmail.com Hello [62.31.61.94]
ProgressInfo: SmtpCmdResp, 250-TURN
ProgressInfo: SmtpCmdResp, 250-SIZE 41943040
ProgressInfo: SmtpCmdResp, 250-ETRN
ProgressInfo: SmtpCmdResp, 250-PIPELINING
ProgressInfo: SmtpCmdResp, 250-DSN
ProgressInfo: SmtpCmdResp, 250-ENHANCEDSTATUSCODES
ProgressInfo: SmtpCmdResp, 250-8bitmime
ProgressInfo: SmtpCmdResp, 250-VRFY
ProgressInfo: SmtpCmdResp, 250-TLS
ProgressInfo: SmtpCmdResp, 250-STARTTLS
ProgressInfo: SmtpCmdResp, 250 OK
ProgressInfo: SmtpCmdSent, STARTTLS<CRLF>
ProgressInfo: SmtpCmdResp, 220 2.0.0 SMTP server ready
ProgressInfo: SslHandshake, StartingProgressInfo: SslHandshake, FinishedProgressInfo: SmtpCmdSent, EHLO DESKTOP-4OHL3UQ<CRLF>
ProgressInfo: SmtpCmdResp, 250-BLU437-SMTP24.smtp.hotmail.com Hello [62.31.61.94]
ProgressInfo: SmtpCmdResp, 250-TURN
ProgressInfo: SmtpCmdResp, 250-SIZE 41943040
ProgressInfo: SmtpCmdResp, 250-ETRN
ProgressInfo: SmtpCmdResp, 250-PIPELINING
ProgressInfo: SmtpCmdResp, 250-DSN
ProgressInfo: SmtpCmdResp, 250-ENHANCEDSTATUSCODES
ProgressInfo: SmtpCmdResp, 250-8bitmime
ProgressInfo: SmtpCmdResp, 250-VRFY
ProgressInfo: SmtpCmdResp, 250-AUTH LOGIN PLAIN XOAUTH2
ProgressInfo: SmtpCmdResp, 250 OK
ProgressInfo: SmtpCmdSent, AUTH LOGIN<CRLF>
ProgressInfo: SmtpCmdResp, 334 VXNlcm5hbWU6
ProgressInfo: SmtpCmdSent, YWp0cnVja2xlQGhvdG1haWwuY28udWs=<CRLF>
ProgressInfo: SmtpCmdResp, 334 UGFzc3dvcmQ6
ProgressInfo: SmtpCmdSent, {PasswordOrCredentials}
ProgressInfo: SmtpCmdResp, 235 2.7.0 Authentication succeeded
ProgressInfo: SmtpCmdSent, MAIL FROM:<truckleaj-software@hotmail.co.uk><CRLF>
ProgressInfo: SmtpCmdSent, RCPT TO:<support@publictalksoftware.co.uk><CRLF>
ProgressInfo: SmtpCmdSent, RCPT TO:<truckleaj-software@hotmail.co.uk><CRLF>
ProgressInfo: SmtpCmdSent, DATA<CRLF>
ProgressInfo: SmtpCmdResp, 250 2.1.0 truckleaj-software@hotmail.co.uk....Sender OK
ProgressInfo: SmtpCmdResp, 250 2.1.5 support@publictalksoftware.co.uk 
ProgressInfo: SmtpCmdResp, 250 2.1.5 truckleaj-software@hotmail.co.uk 
ProgressInfo: SmtpCmdResp, 354 Start mail input; end with <CRLF>.<CRLF>
ProgressInfo: SmtpDataSent, ...ProgressInfo: SmtpCmdSent, <CRLF>.<CRLF>
ProgressInfo: SmtpCmdResp, 250 2.6.0  <1257D95BC7A09B44AA4AF8BC8D3A8036CFF110B9@DESKTOP04OHL3UQ> Queued mail for delivery
ProgressInfo: SmtpCmdSent, QUIT<CRLF>
ProgressInfo: SmtpCmdResp, 221 2.0.0 BLU437-SMTP24.smtp.hotmail.com Service closing transmission channel

Please let me know if there is any data I have shown that should be removed for security. My problems now are:

  1. If I use my SetWindowTitle calls my calling window title bar is not updated? Only the debugstring calls are working.
  2. The percentage handlers were not invoked. Is that expected for sending an email?

Update 2

I tried adding:

mailman.put_HeartbeatMs(80);

Because I read that the PercentDone event is treated like AbortCheck. In addition, I fixed my event callback:

// Percentage completion events may also be overridden to abort time-consuming operations.
void PercentDone(long pctDone, bool *abort)
{
    CString strPercentDone = _T("");
    strPercentDone.Format(_T("PercentDone: %d percent"), pctDone);
    m_dlgLog.AddLogEntry(strPercentDone);
}

But when I check the resulting log I still do not see any PercentDone calls. Is this because my files are too small?

So my questions still stand:

  1. Why is the percent done now showing anything?
  2. How can I show log information whilst the window is processing the mailman (nothing kind of shows). At the moment I am just adding it all into a text string and showing a log afterwards in a popup window.