File attachments

Results 1 to 2 of 2

Thread: File attachments

  1. #1
    Join Date
    Dec 1969

    Default File attachments

    I have discovered a file must exist on the server if you are trying to send email attachments form your home machine but from teh web server.<BR><BR>I found a piece of code that resolved this problem<BR><BR><BR>&#060;%@ Page Language="C#" debug="true" %&#062;<BR>&#060;%@ Import NameSpace="System.Web.Mail" %&#062;<BR>&#060;script runat="server"&#062;<BR>protected void Page_Load(Object Sender, EventArgs e) {<BR>if(!Page.IsPostBack)<BR>Info.Text = "Sending E-Mail using C# ";<BR>}<BR>protected void Send_Email(Object Sender, EventArgs e) {<BR>string sPath = "";<BR>string fileTitle ="";<BR>MailMessage mail = new MailMessage();<BR>mail.To = Request.Form["to"];<BR>mail.From = Request.Form["from"];<BR>if(Request.Form["format"].Equals("text"))<BR>mail.BodyFormat = MailFormat.Text;<BR>else<BR>mail.BodyFormat = MailFormat.Html;<BR><BR>mail.Subject = Request.Form["subject"];<BR>mail.Body = Request.Form["body"];<BR>if(Request.Form["attachment"]!="") <BR>sPath="d:\mywebserveraddressoffiles\<BR>fileTi tle = attachment.PostedFile.FileName;<BR>fileTitle = fileTitle.Substring(fileTitle.LastIndexOf("\") + 1);<BR>attachment.PostedFile.SaveAs(sPath+ fileTitle);<BR>mail.Attachments.Add(new MailAttachment(sPath+fileTitle));<BR>System.IO.Fil e.Delete(sPath+ fileTitle);<BR>try{ SmtpMail.Send(mail); } <BR>catch(Exception MailEx){Info.Text+=MailEx.Message;}<BR>finally{<BR >Info.Text = "Info Sent...<BR><BR>" + "&#060;a href=\"sendMail.aspx\"&#062;Send Another?&#060;/a&#062;";<BR>}<BR>}<BR> <BR><BR>The code appears to work with one problem I get this error:<BR><BR>"Could not access &#039;CDO.Message&#039; object."<BR><BR>I have read around but cannot find a way to fix this error.<BR><BR>Does sanyone know what is wrong in the code?

  2. #2
    Join Date
    Dec 1969

    Default is this a double-post?

    one post is enough.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts