Пример #1
0
        IntPtr GetAttachments(out int fileCount)
        {
            fileCount = 0;
            if (m_attachments == null)
            {
                return(IntPtr.Zero);
            }

            if ((m_attachments.Count <= 0) || (m_attachments.Count >
                                               maxAttachments))
            {
                return(IntPtr.Zero);
            }

            int    size   = Marshal.SizeOf(typeof(MapiFileDesc));
            IntPtr intPtr = Marshal.AllocHGlobal(m_attachments.Count * size);

            MapiFileDesc mapiFileDesc = new MapiFileDesc();

            mapiFileDesc.position = -1;
            int ptr = (int)intPtr;

            foreach (string strAttachment in m_attachments)
            {
                mapiFileDesc.name = Path.GetFileName(strAttachment);
                mapiFileDesc.path = strAttachment;
                Marshal.StructureToPtr(mapiFileDesc, (IntPtr)ptr, false);
                ptr += size;
            }

            fileCount = m_attachments.Count;
            return(intPtr);
        }
Пример #2
0
        public static int SendMail(string strAttachmentFileName, string strSubject, string to)
        {
            IntPtr session   = new IntPtr(0);
            IntPtr winhandle = new IntPtr(0);

            MapiMessage msg = new MapiMessage();

            msg.subject = strSubject;

            int    sizeofMapiDesc = Marshal.SizeOf(typeof(MapiFileDesc));
            IntPtr pMapiDesc      = Marshal.AllocHGlobal(sizeofMapiDesc);

            MapiFileDesc fileDesc = new MapiFileDesc();

            fileDesc.position = -1;
            int ptr = (int)pMapiDesc;

            string path = strAttachmentFileName;

            fileDesc.name = Path.GetFileName(path);
            fileDesc.path = path;
            Marshal.StructureToPtr(fileDesc, (IntPtr)ptr, false);

            msg.files     = pMapiDesc;
            msg.fileCount = 1;


            List <MapiRecipDesc> recipsList = new List <MapiRecipDesc>();
            MapiRecipDesc        recipient  = new MapiRecipDesc();

            recipient.recipClass = 1;
            recipient.name       = to;
            recipsList.Add(recipient);

            int    size   = Marshal.SizeOf(typeof(MapiRecipDesc));
            IntPtr intPtr = Marshal.AllocHGlobal(recipsList.Count * size);

            int recipPtr = (int)intPtr;

            foreach (MapiRecipDesc mapiDesc in recipsList)
            {
                Marshal.StructureToPtr(mapiDesc, (IntPtr)recipPtr, false);
                recipPtr += size;
            }

            msg.recips     = intPtr;
            msg.recipCount = 1;
            int result = MAPISendMail(session, winhandle, msg, MAPI_LOGON_UI | MAPI_DIALOG, 0);

            return(result);
        }
Пример #3
0
        public static int SendMail(string strAttachmentFileName, string strSubject, string to)
        {

            IntPtr session = new IntPtr(0);
            IntPtr winhandle = new IntPtr(0);

            MapiMessage msg = new MapiMessage();
            msg.subject = strSubject;

            int sizeofMapiDesc = Marshal.SizeOf(typeof(MapiFileDesc));
            IntPtr pMapiDesc = Marshal.AllocHGlobal(sizeofMapiDesc);

            MapiFileDesc fileDesc = new MapiFileDesc();
            fileDesc.position = -1;
            int ptr = (int)pMapiDesc;

            string path = strAttachmentFileName;
            fileDesc.name = Path.GetFileName(path);
            fileDesc.path = path;
            Marshal.StructureToPtr(fileDesc, (IntPtr)ptr, false);

            msg.files = pMapiDesc;
            msg.fileCount = 1;


            List<MapiRecipDesc> recipsList = new List<MapiRecipDesc>();
            MapiRecipDesc recipient = new MapiRecipDesc();

            recipient.recipClass = 1;
            recipient.name = to;
            recipsList.Add(recipient);

            int size = Marshal.SizeOf(typeof(MapiRecipDesc));
            IntPtr intPtr = Marshal.AllocHGlobal(recipsList.Count * size);

            int recipPtr = (int)intPtr;
            foreach (MapiRecipDesc mapiDesc in recipsList)
            {
                Marshal.StructureToPtr(mapiDesc, (IntPtr)recipPtr, false);
                recipPtr += size;
            }

            msg.recips = intPtr;
            msg.recipCount = 1;
            int result = MAPISendMail(session, winhandle, msg, MAPI_LOGON_UI | MAPI_DIALOG, 0);

            return result;
        }
Пример #4
0
        IntPtr GetAttachments(out int fileCount)
        {
            fileCount = 0;
            if (m_attachments == null)
                return IntPtr.Zero;

            if ((m_attachments.Count <= 0) || (m_attachments.Count >
                                               maxAttachments))
                return IntPtr.Zero;

            int size = Marshal.SizeOf(typeof(MapiFileDesc));
            IntPtr intPtr = Marshal.AllocHGlobal(m_attachments.Count * size);

            MapiFileDesc mapiFileDesc = new MapiFileDesc();
            mapiFileDesc.position = -1;
            int ptr = (int)intPtr;

            foreach (string strAttachment in m_attachments)
            {
                mapiFileDesc.name = Path.GetFileName(strAttachment);
                mapiFileDesc.path = strAttachment;
                Marshal.StructureToPtr(mapiFileDesc, (IntPtr)ptr, false);
                ptr += size;
            }

            fileCount = m_attachments.Count;
            return intPtr;
        }