16

I have a .Net application. I want this application to send an email to me. How do I implement this without installing an SMTP server?

splattne
  • 102,760
  • 52
  • 202
  • 249
Germstorm
  • 9,709
  • 14
  • 67
  • 83
  • If you need example code, here's some that shows you how to send an email using Gmail's SMTP service. http://gatekiller.co.uk/Post/Send_Emails_with_.NET_and_Gmail – GateKiller Mar 12 '09 at 09:51

3 Answers3

15

Using an SmtpClient to send a MailMessage does not require you to have a server on your local machine.

Your e-mail service provider is the one with the server (e.g. smtp.gmail.com), and your SmtpClient talks to it.

Daniel LeCheminant
  • 50,583
  • 16
  • 120
  • 115
9

This article by Peter Bromberg on eggheadcafe.com

C# SMTP Mail without SMTP Service or CDO

explains how to send email without relying on an SMTP client:

Sending email via TCP using the native SMTP RFC commands "HELO", "MAIL From", RCPT TO", etc. is no big deal. That's one of the first tricks we learn with Telnet. Finding or writing managed code that will do so reliably is another story. The code in the class that follows is not my original code - I've cobbled it together from three different sample sources, fixing namespaces, error handling, and other minor items, changing console code to class library code, and providing a complete Winforms - based test harness front end that illustrates its correct usage.

I've also included sample code to correctly process and add a mail attachment via an OpenFileDialog here. This code MIME encodes and transmits the attachment(s) according to the specification.

bzlm
  • 9,626
  • 6
  • 65
  • 92
splattne
  • 102,760
  • 52
  • 202
  • 249
  • 2
    This still relies on there being an SMTP server on the other end; I'm not sure what benefit you're getting not using SmtpClient and MailMessage... – Daniel LeCheminant Mar 12 '09 at 09:42
  • 2
    Ehm, there always MUST be an SMTP server on the other side. This example shows you sending mail using the SMTP protocol explicitly in your code. – splattne Mar 12 '09 at 09:52
  • @splattne: Okay ... I guess it could be interesting/fun to implement the protocol yourself ;] – Daniel LeCheminant Mar 12 '09 at 10:01
4

You can't send email without the services of a SMTP server, there is of course no need for you to install one, just point your code at your ISPs SMTP server or your companies Exchange server (or what ever they use).

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • 2
    This answer is misleading. It is possible to deliver an email to a recipient without having your own mail server. Connecting to the server identified by the MX record on the recipients domain, and communicating directly. – Brendan May 10 '12 at 18:25
  • @Brendan: I think perhaps you have misread me. I said "without the services of __a__ SMTP server". You say "communicating directly" that is with the server that the MX record for the domain resolves to. That server is __a__ SMTP server. How do you communicate directly with a destination SMTP server? If you try to do so as a client its likely to get upset (or at it least should do) since you are not one of its clients. You could talk to it as if you are a fellow SMTP server but thats a lot of work. – AnthonyWJones May 10 '12 at 22:01
  • 2
    And most sane places prevent this, by blocking outbound port 25, as a spam filtering measure. – tripleee Aug 07 '12 at 10:07