How else can I email a file using ASP.NET?

Posted by Jane T on Stack Overflow See other posts from Stack Overflow or by Jane T
Published on 2010-05-19T09:16:56Z Indexed on 2010/05/19 9:20 UTC
Read the original article Hit count: 242

Filed under:
|
|

Hi all,

I'm using the code below in a ASP.NET page to send a file via email from our users home computer to a mailbox that is used for receiving work that needs photocopying. The code below works fine when sending a file within our network but fails when our users are at home and connected via our SSL VPN, there appears to be a bug in our VPN where it doesn't allow the file to be temporarily saved on the webserver before being sent via email. Can anyone offer any other suggestions on how to attach a file to a ASP.NET page and have the file sent via email without storing it on the web server? Many thanks Jane.

MailMessage mail = new MailMessage();
        mail.From = txtFrom.Text;
        mail.To = txtTo.Text;
        mail.Cc = txtFrom.Text;
        mail.Subject = txtSubject.Text;
        mail.Body = "test"
        mail.BodyFormat = MailFormat.Html;

        string strdir = "E:\\TEMPforReprographics\\"; //<-------PROBLEM AREA
        string strfilename = Path.GetFileName(txtFile.PostedFile.FileName);

        try
        {
            txtFile.PostedFile.SaveAs(strdir + strfilename);
            string strAttachment = strdir + strfilename;

            mail.Attachments.Add(new MailAttachment(strdir + strfilename));
            SmtpMail.SmtpServer = "172.16.0.88";
            SmtpMail.Send(mail);
            Response.Redirect("Thanks.aspx", true);
        }
        catch
        {
           Response.Write("An error has occured sending the email or uplocading the file.");
        }
        finally
        {

        }

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#