コード例 #1
0
ファイル: MAPI.cs プロジェクト: binki/Alba.Framework
        public void SendMail()
        {
            var recipients = new List <MapiRecipDesc>();

            To.ForEach(email => recipients.Add(new MapiRecipDesc {
                recipClass = RecipClass.To, name = email
            }));
            CC.ForEach(email => recipients.Add(new MapiRecipDesc {
                recipClass = RecipClass.CC, name = email
            }));
            BCC.ForEach(email => recipients.Add(new MapiRecipDesc {
                recipClass = RecipClass.BCC, name = email
            }));

            var msg = new MapiMessage {
                subject = Subject, noteText = Body,
                recips  = GetRecipientsData(recipients), recipCount = recipients.Count,
                files   = GetAttachmentsData(Attachments), fileCount = Attachments.Count,
            };

            int result = MAPISendMail(IntPtr.Zero, IntPtr.Zero, msg, MAPI_LOGON_UI | MAPI_DIALOG, 0);

            if (result > 1)
            {
                throw new Exception("Failed to send mail: {0}.".Fmt(GetErrorMessage(result)));
            }
            Cleanup(msg);
        }