Exemple #1
0
        // ----------------------------------------------------------- SENDING ---------

        public bool Send(string sub, string txt, out string aErrInfo)
        {
            lastMsg = new MapiMessage();
            lastMsg.subject = sub;
            lastMsg.noteText = txt;

            // set pointers
            lastMsg.originator = AllocOrigin();
            lastMsg.recips = AllocRecips(out lastMsg.recipCount);
            lastMsg.files = AllocAttachs(out lastMsg.fileCount);

            //error = MAPISendMail(session, winhandle, lastMsg, 0, 0);
            error = MAPISendMail(session, winhandle, lastMsg, MapiDialog, 0);
            Dealloc();
            Reset();

            aErrInfo = GetSendMailErr(error);  // get error details by error code
            //return (error == 0);
            return (error == SUCCESS_SUCCESS) || (error == MAPI_USER_ABORT);  // 0 = SUCCESS_SUCCESS; 1 = MAPI_USER_ABORT
        }
Exemple #2
0
        public bool SaveAttachm(string id, string name, string savepath)
        {
            IntPtr ptrmsg = IntPtr.Zero;
            error = MAPIReadMail(session, winhandle, id,
                                    MapiPeek, 0, ref ptrmsg);
            if ((error != 0) || (ptrmsg == IntPtr.Zero))
                return false;

            lastMsg = new MapiMessage();
            Marshal.PtrToStructure(ptrmsg, lastMsg);
            bool f = false;
            if ((lastMsg.fileCount > 0) && (lastMsg.fileCount < 100) && (lastMsg.files != IntPtr.Zero))
                f = SaveAttachByName(name, savepath);
            MAPIFreeBuffer(ptrmsg);
            return f;
        }
Exemple #3
0
        // ----------------------------------------------------------- FINDING ---------

        public bool Next(ref MailEnvelop env)
        {
            error = MAPIFindNext(session, winhandle, null, findseed,
                                    MapiLongMsgID, 0, lastMsgID);
            if (error != 0)
                return false;
            findseed = lastMsgID.ToString();

            IntPtr ptrmsg = IntPtr.Zero;
            error = MAPIReadMail(session, winhandle, findseed,
                                MapiEnvOnly | MapiPeek | MapiSuprAttach, 0, ref ptrmsg);
            if ((error != 0) || (ptrmsg == IntPtr.Zero))
                return false;

            lastMsg = new MapiMessage();
            Marshal.PtrToStructure(ptrmsg, lastMsg);
            MapiRecipDesc orig = new MapiRecipDesc();
            if (lastMsg.originator != IntPtr.Zero)
                Marshal.PtrToStructure(lastMsg.originator, orig);

            env.id = findseed;
            env.date = DateTime.ParseExact(lastMsg.dateReceived, "yyyy/MM/dd HH:mm", DateTimeFormatInfo.InvariantInfo);
            env.subject = lastMsg.subject;
            env.from = orig.name;
            env.unread = (lastMsg.flags & MapiUnread) != 0;
            env.atts = lastMsg.fileCount;

            error = MAPIFreeBuffer(ptrmsg);
            return error == 0;
        }
Exemple #4
0
        // ----------------------------------------------------------- READING ---------

        public string Read(string id, out MailAttach[] aat)
        {
            aat = null;
            IntPtr ptrmsg = IntPtr.Zero;
            error = MAPIReadMail(session, winhandle, id,
                                    MapiPeek | MapiSuprAttach, 0, ref ptrmsg);
            if ((error != 0) || (ptrmsg == IntPtr.Zero))
                return null;

            lastMsg = new MapiMessage();
            Marshal.PtrToStructure(ptrmsg, lastMsg);

            if ((lastMsg.fileCount > 0) && (lastMsg.fileCount < 100) && (lastMsg.files != IntPtr.Zero))
                GetAttachNames(out aat);

            MAPIFreeBuffer(ptrmsg);
            return lastMsg.noteText;
        }
Exemple #5
0
 private static extern int MAPISendMail(IntPtr sess, IntPtr hwnd,
                                         MapiMessage message,
                                         int flg, int rsv);