What is wrong here?

A

Andrew

Hi, friends,

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

public int SendEmailWithAttachment(string fromEmailAddress,
string toEmailAddress, string subject, string message, string attachment)
{
System.Web.Mail.MailMessage mm = new System.Web.Mail.MailMessage();
mm.From = fromEmailAddress;
mm.To = toEmailAddress;
mm.Subject = subject;
mm.Body = message;
mm.BodyFormat = System.Web.Mail.MailFormat.Text;
mm.Priority = System.Web.Mail.MailPriority.Normal;
mm.BodyEncoding = System.Text.Encoding.Default;
mm.UrlContentBase = "";
mm.UrlContentLocation = "";

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

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

It works fine if there is only one attachment file. However, if there are
two or more files, 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.
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top