I have an error while sending email through batch job "unable to create CLR object". The code works fine if there's no attachment,Permissions are OK on files and directories where attachments are located.
Here's my code:
permissionSet = new Set(Types::Class);
permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
permissionSet.add(new FileIOPermission(_filename, 'rw'));
CodeAccessPermission::assertMultiple(permissionSet);
smtpClient = new System.Net.Mail.SmtpClient();
smtpClient.set_Port(25);
smtpClient.set_DeliveryMethod(System.Net.Mail.SmtpDeliveryMethod::Network);
smtpClient.set_UseDefaultCredentials(true);
smtpClient.set_Host('smtp-out.adista.fr');
mail = new System.Net.Mail.MailMessage(sendFrom,sendTo);
mail.set_Subject(subject);
mail.set_IsBodyHtml(true);
mail.set_Body(emailBody);
mailAttachementCollection = mail.get_Attachments();
mailAttachment = new System.Net.Mail.Attachment(filename);
mailAttachementCollection.Add(mailAttachment);
smtpClient.Send(mail);
CodeAccessPermission::revertAssert();
I debugged and the error comes in "mail attachment =new System.Net.Mail.Attachment(filename);" line. Is there a path coding error ? I used UNC path like '\network\directory\file.csv' and @path, hardcoding path and filename with the same error. I tried with sysmailer class and I also have an error while adding attachment. Any ideas? Thanks for any help
regards,