What is wrong here?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew

    #1

    What is wrong here?

    Hi, friends,

    I have a function which send email with attachments as the follows:

    public int SendEmailWithAt tachment(string fromEmailAddres s,
    string toEmailAddress, string subject, string message, string attachment)
    {
    System.Web.Mail .MailMessage mm = new System.Web.Mail .MailMessage();
    mm.From = fromEmailAddres s;
    mm.To = toEmailAddress;
    mm.Subject = subject;
    mm.Body = message;
    mm.BodyFormat = System.Web.Mail .MailFormat.Tex t;
    mm.Priority = System.Web.Mail .MailPriority.N ormal;
    mm.BodyEncoding = System.Text.Enc oding.Default;
    mm.UrlContentBa se = "";
    mm.UrlContentLo cation = "";

    if (attachment.Tri m() != "")
    {
    char[] delim = new char[] {','};
    foreach (string sSubstr in attachment.Spli t(delim))
    {
    System.Web.Mail .MailAttachment ma = new
    System.Web.Mail .MailAttachment (sSubstr);
    mm.Attachments. Add(ma);
    }
    }

    System.Web.Mail .SmtpMail.SmtpS erver = ""; //default
    System.Web.Mail .SmtpMail.Send( mm);
    return 1;
    }

    It works fine if the if (attachment.Tri m() != "") {...} block is NOT
    executed. However, if this block IS executed (i.e., having attachment), I got
    an error saying:
    Could not access 'CDO.Message' object.

    But, I really could not find what was wrong. Any ideas, suggestions, etc.?
    Thanks a lot.


Working...