protected static void CreateAndSubmitMessage(MapiFolder folder, string sourceMailboxName, string targetMailAddress, string subject, bool deleteAfterSubmit) { using (MapiMessage mapiMessage = folder.CreateMessage()) { PropValue[] props = new PropValue[] { new PropValue(PropTag.DeleteAfterSubmit, deleteAfterSubmit), new PropValue(PropTag.Subject, subject), new PropValue(PropTag.ReceivedByEmailAddress, targetMailAddress), new PropValue(PropTag.Body, "This is a Test-Mailflow probe message.") }; mapiMessage.SetProps(props); mapiMessage.ModifyRecipients(ModifyRecipientsFlags.AddRecipients, new AdrEntry[] { new AdrEntry(new PropValue[] { new PropValue(PropTag.EmailAddress, targetMailAddress), new PropValue(PropTag.OriginatorDeliveryReportRequested, deleteAfterSubmit), new PropValue(PropTag.AddrType, "SMTP"), new PropValue(PropTag.RecipientType, RecipientType.To), new PropValue(PropTag.DisplayName, sourceMailboxName) }) }); mapiMessage.SaveChanges(); mapiMessage.SubmitMessage(SubmitMessageFlags.ForceSubmit); } }
private uint CreateMsgWithAttachement(out byte[] entryId) { ASCIIEncoding asciiencoding = new ASCIIEncoding(); uint @int; using (MapiMessage mapiMessage = this.testFolder.CreateMessage()) { PropValue[] props = new PropValue[] { new PropValue(PropTag.Subject, string.Format("CITestSearch: {0}.", this.searchString)), new PropValue(PropTag.Body, string.Format("The unique search string in the body is: {0}.", this.searchString)), new PropValue(PropTag.MessageDeliveryTime, (DateTime)ExDateTime.Now) }; this.threadExit.CheckStop(); mapiMessage.SetProps(props); int num; using (MapiAttach mapiAttach = mapiMessage.CreateAttach(out num)) { string s = string.Format("This is a test msg created by test-search task (MSExchangeSearch {0}).It will be deleted soon...", this.searchString); byte[] bytes = asciiencoding.GetBytes(s); using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.Create)) { mapiStream.Write(bytes, 0, bytes.Length); mapiStream.Flush(); this.threadExit.CheckStop(); } props = new PropValue[] { new PropValue(PropTag.AttachFileName, "CITestSearch.txt"), new PropValue(PropTag.AttachMethod, AttachMethods.ByValue) }; mapiAttach.SetProps(props); mapiAttach.SaveChanges(); } this.threadExit.CheckStop(); mapiMessage.SaveChanges(); entryId = mapiMessage.GetProp(PropTag.EntryId).GetBytes(); @int = (uint)mapiMessage.GetProp(PropTag.DocumentId).GetInt(); } return(@int); }