Example #1
0
        // ----------------------------------------------------------- SENDING ---------

        public bool Send(string sub, string txt)
        {
            lastMsg          = new Win32.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 = Win32.MAPI32.MAPISendMail(session, winhandle, lastMsg, 0, 0);
            Dealloc();
            Reset();
            return(error == 0);
        }
Example #2
0
        public bool SaveAttachm(string id, string name, string savepath)
        {
            IntPtr ptrmsg = IntPtr.Zero;

            error = Win32.MAPI32.MAPIReadMail(session, winhandle, id,
                                              Win32.MAPI32.MapiPeek, 0, ref ptrmsg);
            if ((error != 0) || (ptrmsg == IntPtr.Zero))
            {
                return(false);
            }

            lastMsg = new Win32.MapiMessage();
            Marshal.PtrToStructure(ptrmsg, lastMsg);
            bool f = false;

            if ((lastMsg.fileCount > 0) && (lastMsg.fileCount < 100) && (lastMsg.files != IntPtr.Zero))
            {
                f = SaveAttachByName(name, savepath);
            }
            Win32.MAPI32.MAPIFreeBuffer(ptrmsg);
            return(f);
        }
Example #3
0
        // ----------------------------------------------------------- READING ---------

        public string Read(string id, out MailAttach[] aat)
        {
            aat = null;
            IntPtr ptrmsg = IntPtr.Zero;

            error = Win32.MAPI32.MAPIReadMail(session, winhandle, id,
                                              Win32.MAPI32.MapiPeek | Win32.MAPI32.MapiSuprAttach, 0, ref ptrmsg);
            if ((error != 0) || (ptrmsg == IntPtr.Zero))
            {
                return(null);
            }

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

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

            Win32.MAPI32.MAPIFreeBuffer(ptrmsg);
            return(lastMsg.noteText);
        }
Example #4
0
        // ----------------------------------------------------------- FINDING ---------

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

            IntPtr ptrmsg = IntPtr.Zero;

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

            lastMsg = new Win32.MapiMessage();
            Marshal.PtrToStructure(ptrmsg, lastMsg);
            Win32.MapiRecipDesc orig = new Win32.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 & Win32.MAPI32.MapiUnread) != 0;
            env.atts    = lastMsg.fileCount;

            error = Win32.MAPI32.MAPIFreeBuffer(ptrmsg);
            return(error == 0);
        }
Example #5
0
        // ----------------------------------------------------------- SENDING ---------
        public bool Send( string sub, string txt )
        {
            lastMsg				= new Win32.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 = Win32.MAPI32.MAPISendMail( session, winhandle, lastMsg, 0, 0 );
            Dealloc();
            Reset();
            return error == 0;
        }
Example #6
0
        public bool SaveAttachm( string id, string name, string savepath )
        {
            IntPtr ptrmsg = IntPtr.Zero;
            error = Win32.MAPI32.MAPIReadMail( session, winhandle, id,
                Win32.MAPI32.MapiPeek, 0, ref ptrmsg );
            if( (error != 0) || (ptrmsg == IntPtr.Zero) )
                return false;

            lastMsg = new Win32.MapiMessage();
            Marshal.PtrToStructure( ptrmsg, lastMsg );
            bool f = false;
            if( (lastMsg.fileCount > 0) && (lastMsg.fileCount < 100) && (lastMsg.files != IntPtr.Zero) )
                f = SaveAttachByName( name, savepath );
            Win32.MAPI32.MAPIFreeBuffer( ptrmsg );
            return f;
        }
Example #7
0
 public void Reset()
 {
     findseed = null;
     origin = new Win32.MapiRecipDesc();
     recpts.Clear();
     attachs.Clear();
     lastMsg = null;
 }
Example #8
0
        // ----------------------------------------------------------- READING ---------
        public string Read( string id, out MailAttach[] aat )
        {
            aat = null;
            IntPtr ptrmsg = IntPtr.Zero;
            error = Win32.MAPI32.MAPIReadMail( session, winhandle, id,
                Win32.MAPI32.MapiPeek | Win32.MAPI32.MapiSuprAttach, 0, ref ptrmsg );
            if( (error != 0) || (ptrmsg == IntPtr.Zero) )
                return null;

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

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

            Win32.MAPI32.MAPIFreeBuffer( ptrmsg );
            return lastMsg.noteText;
        }
Example #9
0
        // ----------------------------------------------------------- FINDING ---------
        public bool Next( ref MailEnvelop env )
        {
            error = Win32.MAPI32.MAPIFindNext(	session, winhandle, null, findseed,
                Win32.MAPI32.MapiLongMsgID, 0, lastMsgID );
            if( error != 0 )
                return false;
            findseed = lastMsgID.ToString();

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

            lastMsg = new Win32.MapiMessage();
            Marshal.PtrToStructure( ptrmsg, lastMsg );
            Win32.MapiRecipDesc orig = new Win32.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 & Win32.MAPI32.MapiUnread) != 0;
            env.atts	= lastMsg.fileCount;

            error = Win32.MAPI32.MAPIFreeBuffer( ptrmsg );
            return error == 0;
        }