int SendMail(string strSubject, string strBody, int how) { MapiMessage msg = new MapiMessage { subject = strSubject, 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); Cleanup(ref msg); return m_lastError; }
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; }
public bool SendMail(string strSubject, string strBody) { MapiMessage msg; 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, MAPI_LOGON_UI | MAPI_DIALOG, 0); if (m_lastError > 1) { MessageBox.Show("MAPISendMail failed! " + GetLastError(), "MAPISendMail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Cleanup(ref msg); return false; } Cleanup(ref msg); return true; }
void Cleanup(ref MapiMessage msg) { int size = Marshal.SizeOf(typeof(MapiRecipDesc)); int ptr; if(msg.recips != IntPtr.Zero) { ptr = (int)msg.recips; for(int i = 0; i < msg.recipCount; i++) { Marshal.DestroyStructure((IntPtr)ptr, typeof(MapiRecipDesc)); ptr += size; } Marshal.FreeHGlobal(msg.recips); } if(msg.files != IntPtr.Zero) { size = Marshal.SizeOf(typeof(MapiFileDesc)); ptr = (int)msg.files; for(int i = 0; i < msg.fileCount; i++) { Marshal.DestroyStructure((IntPtr)ptr, typeof(MapiFileDesc)); ptr += size; } Marshal.FreeHGlobal(msg.files); } m_recipients.Clear(); m_attachments.Clear(); m_lastError = 0; }
static extern int MAPISendMail(IntPtr sess, IntPtr hwnd, MapiMessage message, int flg, int rsv);