简体   繁体   English

如何在WPF项目中检查是否已使用MAPI发送邮件?

[英]How do I check if a mail has been sent using MAPI in a WPF-Project?

I am not able to know if the user has sent the mail or aborted the process. 我无法知道用户是否已发送邮件或中止了该过程。

I am working on a WPF-Project that encrypts files in aes-256 and opens an Outlook-popup where you can send the encrypted file. 我正在开发一个WPF-Project,用于加密aes-256中的文件,并打开一个Outlook-popup,您可以在其中发送加密文件。 To decrypt the file a Code is needed which is sent by SMS to the Person but if the mail hasn't been sent the SMS shouldn't be sent either. 要解密文件,需要通过SMS发送给Person的代码,但如果邮件尚未发送,则不应发送SMS。 The problem is that I can't find a way to determine it. 问题是我无法找到确定它的方法。

try
{
    SendMail(zipfile + ".aes");
    if (mapi.sent == true)
        SendNewSms();           //do not send the SMS if the email has not been sent
    else if (mapi.sent == false)
        MessageBox.Show("It didn't work!!");
}
catch
{
    MessageBox.Show("Error: MAIL");
}

public void SendMail(string attachment)
{
    string subject = "";
    string body = "";
    string attachmentPath = attachment;

    mapi.AddAttachment(attachmentPath);
    mapi.SendMailPopup(subject, body);
}

The MAPI class has this Code that is supposed to send the Mail. MAPI类具有应该发送邮件的此代码。 The "sent" variable is a boolean I added myself “sent”变量是我自己添加的布尔值

[DllImport("MAPI32.DLL")]
static extern int MAPISendMail(IntPtr sess, IntPtr hwnd, MapiMessage message, int flg, int rsv);

int SendMail(string strSubject, string strBody, int how)
{
    MapiMessage msg = new MapiMessage();
    msg.subject = strSubject;
    msg.noteText = strBody;

    msg.recips = GetRecipients(out msg.recipCount);
    msg.files = GetAttachments(out msg.fileCount);

    m_lastError = MAPISendMail(new IntPtr(0), new IntPtr(0), msg, how,
        0);
    if (m_lastError > 1)
        MessageBox.Show("MAPISendMail failed! " + GetLastError(), "MAPISendMail");

    Cleanup(ref msg);
    return m_lastError;
}

My expectation was that the boolean would be set on true if the mail has been sent else it would stay on false. 我的期望是如果邮件已被发送,布尔值将设置为true,否则它将保持为false。

I hope it's written understandable! 我希望它的书面理解可以理解!

Simple MAPI doesn't provide any indication of whether a message is sent. 简单MAPI不提供是否发送消息的任何指示。 However, you may track the Sent Items folder changes. 但是,您可以跟踪“已发送邮件”文件夹更改。 As soon as the item is added to the folder, your message has been sent. 项目添加到文件夹后,您的邮件就会被发送。

In the Outlook Object Model, you can find the MailItem.Sent property which returns a Boolean value that indicates if a message has been sent. 在Outlook对象模型中,您可以找到MailItem.Sent属性,该属性返回一个布尔值,指示是否已发送消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM