I create a functionality to send email. After it has been sent, I want to attach the attachment files that user sent with email back to record. And here is my code.
public static void AddToLog(Common _originatingRecord
, System.Net.Mail.MailMessage _message = null)
{
System.Net.Mail.AttachmentCollection attachmentCollection;
System.Net.Mail.Attachment attachment;
System.Collections.IEnumerator enumerator;
if(_message)
{
attachmentCollection = _message.Attachments;
enumerator = attachmentCollection.GetEnumerator();
while(enumerator.MoveNext())
{
attachment = enumerator.Current;
DocumentManagement::attachFile( _originatingRecord.TableId
, _originatingRecord.RecId
, _originatingRecord.DataAreaId
, "File"
, attachment.ContentStream
, attachment.Name
, System.Web.MimeMapping::GetMimeMapping(attachment.Name)
, System.IO.Path::GetFileNameWithoutExtension(attachment.Name));
}
}
}
DocuRef record is created without file content.
What's wrong in my code