MailMessage

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

Can the MailMessage class be used to send emails from a machine that has
no email account (such as Outlook)?


Mike
 
Mike said:
Can the MailMessage class be used to send emails from a machine that has
no email account (such as Outlook)?

I've not used this, but it looks like you would also need the
System.Web.Mail.SmtpMail class to do the actual transporting of the mail.
That class contains a SmtpServer member which is the name of the server to
relay the message. So (from the description), you should be able to compose
and send an e-mail message with little trouble.

--
/*-------------------------------------
* Tomas Vera
* (e-mail address removed)
* (e-mail address removed)
*-----------------------------------*/
 
It is capable of doing so, but you will have to declare
the SMTP server. Tomas Vera touched on that in his
response, here's a snippet of code I use in a program to
send an email which works great.

/// <summary>
/// Sends an email using the SMTP service.
/// </summary>
/// <param name="sServer">SMTP server to send to</param>
/// <param name="sFrom">Email sending from</param>
/// <param name="sTo">Email sending to</param>
/// <param name="sSubject">Subject of the email</param>
/// <param name="sBody">Body of the email</param>
/// <returns>True if sent successfully, false if an error
occured</returns>
public bool SMTPSend(string sServer, string sFrom, string
sTo, string sSubject, string sBody)
{
try
{
// Build the MailMessage object
MailMessage oMessage = new MailMessage();
oMessage.From = sFrom;
oMessage.To = sTo;
oMessage.Subject = sSubject;
oMessage.Body = sBody;

// Set the SMTP server and send the
message.
SmtpMail.SmtpServer = sServer;
SmtpMail.Send(oMessage);

// If we got this far, it was sent
successfully.
return true;
}
catch
{
// An error occured, so return false
instead.
return false;
}
}

Hope this helps!

- Chris
 
Hi All,

System..Mail namespace uses CDO (Colleborate Data Object) SYS which come
with out look (if I am correct it won't work with win 98) so if you need to
avoid that, you may have to write the send method from the scratch.. I saw
there are samples on the web discribes how to send mail without CDO SYS

Nirosh.
 
Back
Top