Sending email through SMTP server

Connect via a Socket class, then you'll need to have the following conversation with the SMTP server (port 25):

Code:
< 220 Ready
> MAIL FROM:myemail@mydomain.com
< 250 Sender ok
> RCPT TO:recipient@domain.com
< 250 Recipient ok
> DATA
< 354 Ok Send data ending with <CRLF>.<CRLF>
> sample email line!
> .
< 250 Ok, sent
> QUIT
< 221

I suggest you read the SMTP RFC for more information on the protocol.
 
Many thanks for your answer, could you specify me more (or give any link) about the socket class connection, I'm really newbie to that. Thanks again.

In fact, what I seem in your code is that it's very like a TELNET sending of an email, but, what I really don't know is how to make that code to function automatized by VB application.
 
Yes, it's a TCP connection just like a telnet one. There are .NET classes under System.Web.Mail but you said you wanted to send one directly using an SMTP server so I assumed you wanted to do it manually.

There are examples of using the Socket class in the documentation and samples in the SDK.
 
Well, actually I think that manually is the best way, here it is what I need to do:

I need to send through an email just one string, but, I need to do it automatized way, what I will send and where I'm going to send it are constants, so, I don't need to enter them ("to" and "data") every time it will be sent. Now, you tell me, what's the best for me?, maybe I could use System.Web.Mail class, in fact, it sounds much more easier for what I need, but using this class I can set the target (TO) and the content (DATA) and send it without disturbing my user (of the application)?. :)
 
Straight from the help:

Visual Basic:
Dim from As String = "from@microsoft.com"
Dim mailto As String = "to@microsoft.com"
Dim subject As String = "UtilMailMessage001"
Dim body As String = "<html><body>UtilMailMessage001 - success</body></html>"
SmtpMail.Send(from, mailto, subject, body)

C#:
string from = "from@microsoft.com";
string to = "to@microsoft.com";
string subject = "UtilMailMessage001";
string body = "<html><body>UtilMailMessage001 - success</body></html>";
SmtpMail.Send(from, to, subject, body);
 
Well, the code that divil gave me didn't work, it doesn't recognizer SMTPMail.xxxxxx as a function or a class.

In the other side, there's a weird thing that's happening, I read what Derek gaves to me, about the class System.Web.Mail.SMTP that appears on the help, but IT DOESN'T RECOGNIZES this one either!, I mean, when a start typing System, the VB suggest diferent kinds of options of sub divisions of the class System (as usual), but there's no subdivision Web and of course none of the others sub of the sub, anyway, I installed it complete!, so, I really dunno why is that happening. Any clue?
 
OK, first this you have to do is go to the 'Project' menu and click
'Add Reference'. Find 'System.Web.dll' in the list of references, and
double click it, then click OK. Then the code will work.

Visual Basic:
Dim m As System.Web.Mail.SmtpMail
Dim sFrom, sTo, sSubject, sMessage As String

sFrom = "email@mail.com"
sTo = "email@mail.com"
sSubject = "This is a test"
sMessage = "Blah blah blah"

m.Send(sFrom, sTo, sSubject, sMessage)
 
Back
Top