send an e-mail.

  • Thread starter Thread starter Alberto
  • Start date Start date
As long as you have a valid SMTP server that can relay for you, this will
work:

using System.Web.Mail;

....

MailMessage message = new MailMessage();

message.From = "(e-mail address removed)";
message.To = "(e-mail address removed)";
message.Subject = "Hello";
message.Body = "World";

SmtpMail.SmtpServer = "my.smtpserver.com";
SmtpMail.Send(message);
 
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = true;
p.StartInfo.FileName = "mailto:[email protected] ?subject=xxxx " +
"&body= xxxx";
p.Start();
 
If this code is used, I would have though that this code would only cause
the user's e-mail client to open up.
Does this actually send the mail, or does the user have to then acknowledge
the message?

Clearly, this won't work on a server. Am I mistaken?

--- N
 
I'm probably being dense here as I'm new to C# (forgive me if I am), but
does this code work ??

Just tried, I don’t seem to have a System.Web.Mail namespace ?? Just a
System.Web

Missing the obvious ?? Or is this wrong ??

-----Original Message-----
From: Klaus H. Probst [mailto:[email protected]]
Posted At: 12 July 2004 17:52
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: send an e-mail.
Subject: Re: send an e-mail.


As long as you have a valid SMTP server that can relay for you, this
will
work:

using System.Web.Mail;

....

MailMessage message = new MailMessage();

message.From = "(e-mail address removed)";
message.To = "(e-mail address removed)";
message.Subject = "Hello";
message.Body = "World";

SmtpMail.SmtpServer = "my.smtpserver.com"; SmtpMail.Send(message);
 
Could you tell me how to send an e-mail from a code written in C#?

thank you.

using System;
using System.Web.Mail;

public class MyClass
{
public static void Main()
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = "(e-mail address removed)";
mailMessage.To = "(e-mail address removed)";
mailMessage.Subject = "This is a subject";
mailMessage.Body = "Your message here";
SmtpMail.Send(mailMessage);
}
}

Make sure you add a reference to System.Web.dll and that you have
configured an SMTP server which should be ok if you;re running Outlook
on your machine.
 
Add a reference to System.Web.Mail.

--
Klaus H. Probst, MVP
http://www.vbbox.com/


Dave Sully said:
I'm probably being dense here as I'm new to C# (forgive me if I am), but
does this code work ??

Just tried, I don't seem to have a System.Web.Mail namespace ?? Just a
System.Web

Missing the obvious ?? Or is this wrong ??

-----Original Message-----
From: Klaus H. Probst [mailto:[email protected]]
Posted At: 12 July 2004 17:52
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: send an e-mail.
Subject: Re: send an e-mail.


As long as you have a valid SMTP server that can relay for you, this
will
work:

using System.Web.Mail;

...

MailMessage message = new MailMessage();

message.From = "(e-mail address removed)";
message.To = "(e-mail address removed)";
message.Subject = "Hello";
message.Body = "World";

SmtpMail.SmtpServer = "my.smtpserver.com"; SmtpMail.Send(message);


--
Klaus H. Probst, MVP
http://www.vbbox.com/


Alberto said:
Could you tell me how to send an e-mail from a code written in C#?

thank you.
 
Back
Top