System.Web.Mail

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

After a connection to the server has been established,
an email can be sent ok. However if a connection has not
been previously established, I get a "Could not access
CDO. Message Object" error. Is there a way to overcome
this, i.e., so a message can be sent without first manually
establishing a connection to the server?
 
Ignacio Machin ( .NET/ C# MVP ) said:
hi

post your code.

cheers,

using System;
using System.Web.Mail;

namespace PRL042
{

public class Smtp
{
string from;
string to;
string subject;
string body;
string server;

public Smtp(string from,string to,string subject,string body,string
server)
{
this.from = from;
this.to = to;
this.subject = subject;
this.body = body;
this.server = server;
initialize();
}

void initialize()
{
MailMessage Message = new MailMessage();
Message.To = to;
Message.From = from;
Message.Subject = subject;
Message.Body = body;
SmtpMail.SmtpServer = server;
SmtpMail.Send(Message);
}
}
}
 
Back
Top