I am tasked to send a .csv file via email.
I've searched the web for possible approaches and chose this approach:
Sending email via SMTP using X and .NET Framework in Dynamics AX | Corbitech
the only problem I have is that I am getting the exact same error from this post in this forum:
Send email with attachment - Microsoft Dynamics AX Forum Community Forum
I have searched all possible reason for the error to happen, I made sure that the folder path is accessible, also I tried to to an UNC path for the file and made sure it has access to that path as well. Also, the file is created. I am able to see it.
Why can I write a file to that path, but I can't get the file to attach it?
I also tried instead of using this syntax:
permissionSet = new Set(Types::Class); permissionSet.add(new InteropPermission(InteropKind::ClrInterop)); permissionSet.add(new FileIOPermission(filename, 'rw')); CodeAccessPermission::assertMultiple(permissionSet);
I used this because some articles only used this syntax:
permission = new FileIOPermission(fileName,'r'); permission.assert();
Unfortunately, everything I've researched doesn't work and the code stops at this point:
mailAttachment = new System.Net.Mail.Attachment(fileName);
Removing the line of code above, or commenting it out, it successfully sends an email. This line hinders the code to work.
There's already a lot of articles with no answer to this question, just wanted to post this again and bring it up to put an end to it.
Would like to ask for help on this. Also, is this approach still supported?
EDIT: Additional information, prior to sending an email, I have created a csv file, is it possible that the csv file I have just created cannot be accessed because it is being used by another process? Is there a way where affter creating the csv file, I can close it so no other process is using it?
Here's the version of my AX 2012:
Kernel Version: 6.2.2000.197
Application version: 6.2.1000.1437