whytheq
whytheq

Reputation: 35557

How to send an email using C#?

Looking in this StackOverflow question it uses the following to send emails:

System.Net.Mail.SmtpClient

Is that the easiest approach to use when sending mails from a console application. Outlook is installed in the machine that I'd like to send from - would it be overkill adding a reference and using that namespace?

Apologies for a slightly vague question but my experience is within VBA and in when the VBA resides in Excel I've always used Outlook but in SQLserver I use the following so was wondering if there's something similar in c#:

msdb.dbo.sp_send_dbmail

I am using .Net 4.0

Upvotes: 1

Views: 299

Answers (3)

mgnoonan
mgnoonan

Reputation: 7200

SmtpClient is the way to send an email from your code, if that's where you want the work done. If you want a more server-centric approach, you can use the SQL stored procedure approach.

If you want a proprietary solution that requires you install Outlook where ever you want to run your program, then you can go the Outlook route. I don't recommend it, however.

Upvotes: 1

jason
jason

Reputation: 241641

Best

You didn't tell us your criteria for selecting the best.

System.Net.Mail.SmtpClient is that the easiest approach

It is very easy to use. Interop with Outlook is not easy at all.

would it be overkill adding a reference and using that namespace?

I think so. Unless you need Outlook-specific features, doing this doesn't add any value to your project (it actually subtracts value).

I use the following so was wondering if there's something similar in c#:

System.Net.Mail.SmtpClient

Upvotes: 0

Thorsten Dittmar
Thorsten Dittmar

Reputation: 56697

I'd go for SmtpClient as Outlook Interop is not trivial for C# beginners. If you need a fast solution, use SmtpClient first and spend some spare time on trying to implement the Outlook solution - just for the sake of learning how to do things ;-)

Upvotes: 2

Related Questions