Welcome to the myhosting.com Forums.
Problems occur While sending mail with attachment on myhosting server
I created website using Visual studio 2008 and SP.NET 3.5 version. uplaoding this website into myhosting server of ComputerTekk Inc domain. while sending mail from server its working fine. but sending mail with attachment its getting following error:
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
but sending mail with attachment in localhost working fine. What to do.
please help me.
Thanks in advance.
Hi there, Rajiv. I've escalated this to our Operations team. They'll look into it as soon as possible. When I hear back from them, I'll give you a shout.
Thanks for your patience. Cheers,
Hey Rajiv. Our Operations department looked into this, and tested the page in question. They highlighted this line from the full error message:
VMS.Campaigner.sendmail.btnSubmit_Click(Object sender, EventArgs e) in sendmail.aspx.cs:71
In sendmail.aspx , FileUpload1.Posted on line 70 is an instance of the HttpPostedFile class. This works on the customer's localhost but not on myhosting.com's server (or any other) because HttpPostedFile.FileName is the fully-qualified name of the file on the client's computer
In other words, if C:\file.txt
is uploaded, sendmail.aspx tries to attach that specific file to the email. However, doing so fails because C:\file.txt
doesn't exist on the myhosting.com server.
The customer should:
- Use HttpPostedFile.SaveAs to save the posted file to a temporary file on the server.
- Attach the temporary file to the email.
- Send the email.
- Delete the temporary file.