SMTP Error

y2L

Newcomer
Joined
Nov 18, 2003
Messages
4
I recieve an error message when i try to sent a email using SMTP in my .Net Application.

The error Message says :
Could not access 'CDO.Message' object.

What is the problem ?
Any suggestion or solution ?

Another problem is can I attach an attachment in the email ? Can the attachment be seen in buffer bit data type ?
 
Last edited:
You can add attachments in email using the MailMessage class which is part of the System.Web.Mail class.

Dim attachment As New MailAttachment(......)
 
Ya, I was having the same problem on a win2k machine, also the Smtp class in .net can only be used in win2k and up, so I just made a library to handle stuff like this and some other stuff from previous projects. There's a namespace for sending plain text messages, and another to send MIME emails (to allow sending of file attachments and other cool stuff). Here's a code sample of how I would use my library to send an email with a file attachment.

Code:
using System;
using HB.Web;
using HB.Web.Mail;
using HB.Web.Mail.Mime;
using HB.Web.Ftp;

namespace MailTester
{
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
			//create a mime msg to send file attachments
			MimeMessage msg = new MimeMessage();
			msg.To.Add(new ArpaMailAddress("some@emailaddress.mmk"));
			msg.From = new ArpaMailAddress("another@address.k");
			msg.Subject = "Test email# " + DateTime.Now.Ticks;
			
			//create a file attachment mim part
			FileAttachment attachment = new FileAttachment(@"C:\somefile.bin", msg.Boundary);
			attachment.Encoding = FileAttachment.ContentTransferEncoding.Base64;
			attachment.Disposition = FileAttachment.ContentDisposition.Attachment;

			//create a multipart alternative mime part to add text to the message
			MultipartAlternative text = new MultipartAlternative(MimeMessage.GenerateBoundary(), msg.Boundary);
			text.AddContentType(MultipartAlternative.TextPlain, "Here's the file you wanted.", null);
			
			//add the text part to the mime message
			msg.MimeParts.Add(text);
			//add the file attachment to the mime message
			msg.MimeParts.Add(attachment);

			//send the email
			Smtp.Send("some_server_ip", msg);
		}
	}
}
It can be downloaded here
 
Back
Top