Invalid mail attachment

G

Guest

I have a web service. It creates a email and attached a file sitting one the
network drive \\servername\filename. I tried UNC format and also try to
mapping drive (eg. g:\text.txt or g:\\text.txt). I also check the permission
of the file and file sharing (grant to everyone), I still got the following
err:

Server was unable to process request. --> Invalid mail attachment
'g:\\g:\\text.txt)'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Here is the code:

Dim mailMessage As New System.Web.Mail.MailMessage
Dim emailAttachment As New System.Web.Mail.MailAttachment
mailMessage.To = strSubmissionEmailAddress
mailMessage.Cc = "(e-mail address removed)"
mailMessage.From = "(e-mail address removed)"
mailMessage.Subject = "test"
mailMessage.BodyFormat = System.Web.Mail.MailFormat.Text
mailMessage.Body = pStrMessageBody
mailMessage.Attachments.Add(emailAttachment)

SmtpMail.SmtpServer = strSubmissionSmtpServer
SmtpMail.Send(mailMessage)


Please help! Thank you!
 
G

Guest

By the way, do I have to upload the file to the server and attached the file
locally? or I can attach file from network drive?
 
M

Markus

By the way, do I have to upload the file to the server and attached
the file locally? or I can attach file from network drive?

Well, if the server has access to the file - then you might consider to
leave all execution at the server.

Can you give us the stack trace? Because the error can be manifold:
- SecurityException -> No access to the File
- File Not Found Exception -> Attachement file not found
- Some other coding error, nothing to do with the mail sending, but
causing the error.

However, from the main message, I believe that the path is wrongly
interpreted. Have you also tried the @ before the string?
@"G:\test.txt"?

.... waiting for your feedback
Markus
 
G

Guest

Here is the trace:
Server was unable to process request. --> Invalid mail attachment
'g:\\BVAN025'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.Web.Services.Protocols.SoapException: Server was
unable to process request. --> Invalid mail attachment 'g:\\BVAN025'.

Source Error:


Line 148:
<System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/SubmitEFTFileByMail",
RequestNamespace:="http://tempuri.org/",
ResponseNamespace:="http://tempuri.org/",
Use:=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Line 149: Public Function SubmitEFTFileByMail(ByVal pStrMessageBody
As String, ByVal pStrAttachment As String) As String
Line 150: Dim results() As Object =
Me.Invoke("SubmitEFTFileByMail", New Object() {pStrMessageBody,
pStrAttachment})
Line 151: Return CType(results(0),String)
Line 152: End Function


Source File: C:\VEHICLERENTALSYSTEM\Web\Web
References\EFTService\Reference.vb Line: 150

Stack Trace:


[SoapException: Server was unable to process request. --> Invalid mail
attachment 'g:\\BVAN025'.]

System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)
EFTService.AirMilesEFTService.SubmitEFTFileByMail(String pStrMessageBody,
String pStrAttachment) in C:\VEHICLERENTALSYSTEM\Web\Web
References\EFTService\Reference.vb:150
WebForm1.Page_Load(Object sender, EventArgs e) in
C:\VEHICLERENTALSYSTEM\Web\WebForm1.aspx.vb:35
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
 
G

Guest

When I copy the file to the server where the web service is running, then it
works fine. I am just wondering the file could not be in the network drive.
It has to be in the local drive. Is this true?

Thanks
 
M

Markus

When I copy the file to the server where the web service is running,
then it works fine. I am just wondering the file could not be in the
network drive. It has to be in the local drive. Is this true?

I checked your stack-trace and cannot tell you the solution.

However, I am pretty sure, there are some security/permissions to
consider, because I had also a similar problem a few years ago, but
can't remember, how to resolve it.

But just to get you some ideas: The web service is run under the IIS web
account (or whatever account you have configured). This user must have
permissions to access the remote location. There might be some
additional issues, if you are working in an Active Directory environment...

To check it, try to access the file via code and wrap a try/catch block
around it. Then check the exception in the debugger just to be sure, if
it is really a SecurityException.

try
{
ReadFile();
}
catch (Exception ex)
{
// debug into this line
}

sorry for running out of ideas right now and not being able to help you
out...

Markus
 
G

Guest

My understanding is:
Webmail is running under IIS, so it has no permission to access network file
system.

Let me know if my understanding is wrong.

Thanks
 
M

Markus

My understanding is: Webmail is running under IIS, so it has no
permission to access network file system.

I don't know, what you mean with Webmail - but if you mean anything,
that is running as a website or webservice, then you are right (at least
for the default settings).

However, for testing, you can configure IIS to run under Administrator
rights (bad for production usage, but good for testing). Then, if this
is working, you might consider to setup a user with permissions to the
remote file system.

Additionally, keep in mind that network-drive mappings are user
specific. So just because you have mounted \\server\share1 as G: it does
not mean that the IIS user also has the G: mounted. So you might want to
use the \\server\share1 notation instead of drive mapping.

.... however, I am starting to talk to much guesswork, as I am out of the
web business already a couple of years right now... so you might find a
better answer by searching the internet for "asp.net access file share"
or something similar...

Hope, I could give you at least some ideas.
Markus
 
G

Guest

Hi Markus,
Thank you for your help.

I think it is quite helpful. I acutually realize the issue, I just want to
confirm. After testing, I will let you know exact.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top