Флаг MAPI Thunderbird MAPI_RECEIPT_REQUESTED не работает - PullRequest
0 голосов
/ 24 марта 2020

Мое приложение отправляет электронные письма с Outlook и Thunderbird (версия 68.6.0) через MAPI. Я получаю квитанцию ​​только в том случае, если письма отправляются в Outlook, а не в Thunderbird. mapiMessage.flags = MAPI_RECEIPT_REQUESTED; // Set receipt flag Пожалуйста, кто-нибудь может помочь с запросом чека в Thunderbird? </p> <pre><code>// using System.Runtime.InteropServices; void button1_Click(object sender, EventArgs e) { try { SendMail(new List<Recipient> { new Recipient { Name = "test@gamil.com", RecipClass = RecipientType.To } }, "Subject", "Body"); } catch (Exception ex) { MessageBox.Show($"{ex}"); }; } [DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)] static extern uint MAPILogon(IntPtr ulUIParam, string lpszProfileName, string lpszPassword, uint flFlags, uint ulReserved, ref IntPtr lplhSession); [DllImport("MAPI32.DLL")] static extern uint MAPILogoff(IntPtr sess, IntPtr hwnd, uint flg, uint rsv); [DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)] static extern uint MAPISendMail(IntPtr lhSession, IntPtr hwnd, MapiMessage lpMessage, uint flFlags, uint ulReserved); const int MAPI_LOGON_UI = 0x00000001; const int MAPI_RECEIPT_REQUESTED = 0x00000002; enum RecipientType { Originator = 0, To, Cc, Bcc }; [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] class Recipient { public int Reserved = 0; public RecipientType RecipClass = RecipientType.Originator; public string Name; public string Address; public int IdSize = 0; public IntPtr EntryID = IntPtr.Zero; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] class MapiMessage { public int reserved; public string subject; public string noteText; public string messageType; public string dateReceived; public string conversationID; public int flags; public IntPtr originator; public int recipCount; public IntPtr recips; public int fileCount; public IntPtr files; } void SendMail(List<Recipient> recipients, string subject, string body) { // Logon // First call to MAPILogon with ProfileName = null, Password = null and [Logon]Flags = 0: MapiLogon uses existing session, if exists var session = IntPtr.Zero; var result = MAPILogon(IntPtr.Zero, null, null, 0, 0, ref session); if (result != 0) result = MAPILogon(IntPtr.Zero, null, null, MAPI_LOGON_UI, 0, ref session); if (result != 0) throw new Exception($"Error Logon: {result}"); // MAPILogon throws exception, refer to GetErrorText() // Send mail var mapiMessage = new MapiMessage { subject = subject, noteText = body }; mapiMessage.recips = GetRecipients(recipients, out mapiMessage.recipCount); mapiMessage.flags = MAPI_RECEIPT_REQUESTED; // Set receipt flag result = MAPISendMail(session, IntPtr.Zero, mapiMessage, 0, 0); if (result > 1 || result < 0) throw new Exception($"Error SendMail: {result}"); // Cleanup(ref mapiMessage); // Logoff if (session != IntPtr.Zero) { result = MAPILogoff(session, IntPtr.Zero, 0, 0); if (result != 0) throw new Exception($"Error Logoff: {result}"); } } IntPtr GetRecipients(List<Recipient> recipients, out int recipCount) { recipCount = 0; if (recipients.Count == 0) return IntPtr.Zero; var size = Marshal.SizeOf(typeof(Recipient)); var intPtr = Marshal.AllocHGlobal(recipients.Count * size); var ptr = (int)intPtr; foreach (var mapiDesc in recipients) { Marshal.StructureToPtr(mapiDesc, (IntPtr)ptr, false); ptr += size; } recipCount = recipients.Count; return intPtr; }

...