Sending mail without installing an SMTP server
Solution 1
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.
Solution 2
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.
Solution 3
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).
Stefano
I'm a software developer. I like web comics, TV-shows, movies, PC games and books. Read my blog if you want to find out more about me.
Updated on February 07, 2020Comments
-
Stefano over 4 years
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?
-
GateKiller about 15 yearsIf you need example code, here's some that shows you how to send an email using Gmail's SMTP service. gatekiller.co.uk/Post/Send_Emails_with_.NET_and_Gmail
-
Stefano about 15 years@GateKiller: Thank you for the link, I appreciate it
-
-
Daniel LeCheminant about 15 yearsThis 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...
-
splattne about 15 yearsEhm, 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.
-
Daniel LeCheminant about 15 years@splattne: Okay ... I guess it could be interesting/fun to implement the protocol yourself ;]
-
Brendan about 12 yearsThis 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.
-
AnthonyWJones about 12 years@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.
-
tripleee almost 12 yearsAnd most sane places prevent this, by blocking outbound port 25, as a spam filtering measure.