|
19.08.2014, 17:23 | #1 |
Участник
|
Несколько вложений для письма. Нужен пример кода
Добрый день!
Есть код, который без проблем делает один аттачмент, но вот пару - никак. Может кто-то поделится? Вот мой код X++: public void SendEmail(Entity PrimaryEntity, IOrganizationService service, Dictionary<string, string> FileNameDictionary) { var ClientId = PrimaryEntity.Id; var ownerId = ((EntityReference)PrimaryEntity.Attributes["ownerid"]).Id; Entity owner = service.Retrieve("systemuser", ownerId, new Microsoft.Xrm.Sdk.Query.ColumnSet(true)); String ownerName = (String)owner.Attributes["fullname"]; String subject = "The document has been created by " + ownerName + "<br><br>"; subject = subject + "The following document are required in the Contact.<br><br>"; ActivityParty fromParty = new ActivityParty { PartyId = new EntityReference(SystemUser.EntityLogicalName, ownerId) }; ActivityParty toParty = new ActivityParty { PartyId = new EntityReference(SystemUser.EntityLogicalName, ownerId) }; Email email = new Email(); email.RegardingObjectId = new EntityReference("contact", ClientId); email.To = new ActivityParty[] { toParty }; email.From = new ActivityParty[] { fromParty }; email.Subject = "Report"; email.Description = subject; email.DirectionCode = true; foreach (var FileNameDic in FileNameDictionary) { email.email_activity_mime_attachment = new[] { AttachFileToEmail(FileNameDic.Key, FileNameDic.Value) }; /*email.email_activity_mime_attachment = new[] { AttachFileToEmail(FileNameDic.Key, FileNameDic.Value) };*/ } Guid EmailId = service.Create(email); SendEmailRequest req = new SendEmailRequest(); req.EmailId = EmailId; req.IssueSend = true; req.TrackingToken = ""; SendEmailResponse res = (SendEmailResponse)service.Execute(req); } public ActivityMimeAttachment AttachFileToEmail(string fileName, string OutputFileName) { var fileLocation = OutputFileName; var stream = File.OpenRead(fileLocation); var byteData = new byte[stream.Length]; stream.Read(byteData, 0, byteData.Length); var encodedData = Convert.ToBase64String(byteData); var extension = Path.GetExtension(fileLocation).ToLower(); String mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; var sampleAttachment = new ActivityMimeAttachment { ObjectId = new EntityReference(Email.EntityLogicalName, EmailId), ObjectTypeCode = Email.EntityLogicalName, FileName = fileName, MimeType = mimeType, Body = encodedData, }; stream.Close(); return sampleAttachment; } |
|
19.08.2014, 17:33 | #2 |
Чайный пьяница
|
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством. Подписывайтесь на мой блог, twitter и YouTube канал. Пользуйтесь моим Ultimate Workflow Toolkit |
|