Send email using C#?

A

Alain Dekker

Anybody know of a way to send email (using a SMTP server, I guess) using C#?
I'd probably need to use SSL encryption.

Thanks,
Alain
 
A

Arne Vajhøj

Anybody know of a way to send email (using a SMTP server, I guess) using C#?
I'd probably need to use SSL encryption.

Example:

using System;
using System.Net.Mail;

namespace DefaultNamespace
{
public class MainClass
{
public static void Main(string[] args)
{
SmtpClient Server = new SmtpClient("arne");
MailMessage Mailer = new MailMessage();
Mailer.From = new MailAddress("arne@arne");
Mailer.To.Add(new MailAddress("arne@arne"));
Mailer.Subject = "Test";
Mailer.Body = "Dette er en test\r\nlinie 2\r\nlinie 3";
Server.Send(Mailer);
}
}
}

Arne
 
J

Jeff Johnson

The simplest method would be to use the email client that already is
configured on the machine and the one the user are used to.

You just need one statement for that:

System.Diagnostics.Process.Start("mailto:[email protected]?subject=Testing
email from C#&body=First paragraph of message%0A%0aSecond paragraph.");

I'm quite sure he doesn't want an email message to pop up and the user to
have to hit the Send button. Also, not all clients honor the "body" part.
 
L

Lee J. Moore

I'm quite sure he doesn't want an email message to pop up and the user
to have to hit the Send button. Also, not all clients honor the "body"
part.


It's an OK solution if you're writing for a single client with a
predictable setup (assuming they don't mind this behaviour), but yeah, not
everybody even has a default email client configured now that webmail
accounts are so prolific, so it's pretty much asking for trouble if being
deployed to multiple users.

I personally hate it when clicking a contact link on a website results in
the email client being launched, and I'd like that behaviour even less in
an application.
 
M

mick

Lee J. Moore said:
It's an OK solution if you're writing for a single client with a
predictable setup (assuming they don't mind this behaviour), but yeah, not
everybody even has a default email client configured now that webmail
accounts are so prolific, so it's pretty much asking for trouble if being
deployed to multiple users.

I personally hate it when clicking a contact link on a website results in
the email client being launched, and I'd like that behaviour even less in
an application.

Not LJM from tv.misc in the olden days is it?:) Blast from the past if so.

mick
 
L

Lee J. Moore

Not LJM from tv.misc in the olden days is it?:) Blast from the past if
so.

Oh hello! Yes it's me. Nice to see you again. ;)

Yes, I've been checking out the graveyard that is usenet after about five
years away. Strange how much it's shrunk. Some hierarchies seem deader
than they were in the early 1990s.
 

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

Top