Я изменяю только несколько строк, поскольку, имя файла в этом случае - stati c, но вы можете изменить его позже.
if (NotesAttachment.Contains("filename"))
EmailAttachment["filename"] = "abc.pdf";
if (NotesAttachment.Contains("documentbody"))
EmailAttachment["body"] = Convert.ToBase64String(NotesAttachment.GetAttributeValue<string>("documentbody"));
if (NotesAttachment.Contains("mimetype"))
EmailAttachment["mimetype"] = "text/plain";
Попробуйте следующий код,
Entity emailCreated = service.Retrieve("email", SourceEmailID, new ColumnSet(true));
QueryExpression QueryNotes = new QueryExpression("annotation");
QueryNotes.ColumnSet = new ColumnSet(new string[] { "subject", "mimetype", "filename", "documentbody" });
QueryNotes.Criteria = new FilterExpression();
QueryNotes.Criteria.FilterOperator = LogicalOperator.And;
QueryNotes.Criteria.AddCondition(new ConditionExpression("objectid", ConditionOperator.Equal, invoiceID.Id));
EntityCollection MimeCollection = service.RetrieveMultiple(QueryNotes);
if (MimeCollection.Entities.Count > 0)
{ //we need to fetch first attachment
Entity NotesAttachment = MimeCollection.Entities.First();
//Create email attachment
Entity EmailAttachment = new Entity("activitymimeattachment");
if (NotesAttachment.Contains("subject"))
EmailAttachment["subject"] = NotesAttachment.GetAttributeValue<string>("subject");
EmailAttachment["objectid"] = new EntityReference("email", emailCreated.Id);
EmailAttachment["objecttypecode"] = "email";
if (NotesAttachment.Contains("filename"))
EmailAttachment["filename"] = "abc.pdf";
if (NotesAttachment.Contains("documentbody"))
EmailAttachment["body"] = Convert.ToBase64String(NotesAttachment.GetAttributeValue<string>("documentbody"));
if (NotesAttachment.Contains("mimetype"))
EmailAttachment["mimetype"] = "text/plain";
service.Create(EmailAttachment);
}
// Sending email
SendEmailRequest SendEmail = new SendEmailRequest();
SendEmail.EmailId = emailCreated.Id;
SendEmail.TrackingToken = "";
SendEmail.IssueSend = true;
SendEmailResponse res = (SendEmailResponse)service.Execute(SendEmail);