Scenario 1: Message queue directory is local.
This is an NTFS permission problem. The current user (such as IUSR_machinename)
must have Full Control over the queue directory to be able to create files in it.
You can instantly fix this problem by giving Everyone Full Control over
the queue directory, then tighten security as appropriate. To change permissions
on a folder, right-click on it in Windows Explorer, then select Properties/Security.
Scenario 2: Queue directory is remote.
To avoid the Access is Denied error when writing to a remote UNC path such as \\server\share\dir, you should call the method Mail.LogonUser
to impersonate an admin account, as follows:
Mail.LogonUser "domain", "username", "password"
Also, EmailAgent must have full control over the queue directory, or your messages will not be sent. Usually this is not a problem because EmailAgent installs as a service under a SYSTEM user context. But if you have tight security settings on your machine, you may need to check that the system has full control over the directory, or possibly assign EmailAgent to another user context in System Services.