SMTP is the simple mail transfer protocol. You use it to send e-mails over a server.
It is like a question & answer game, you ask the server and he answers you.
So, first you connect with a winsock control:
Winsock1.RemoteHost = post.server.com 'Use the servers address you want to use
Winsock1.LocalPort = 25 'SMTP uses port 25
Winsock1.Protocol = 0 'Use TCP/IP
Winsock1.Connect
Then you get a string from the server, my server says:
220 post.webmailer.de ESMTP Sendmail 8.9.3/8.8.7; Sun, 20 May 2001 21:51:57 +0200 (MET DST)
You answer:
HELO floppes 'means, "hello, I am floppes"
Server:
250 post.webmailer.de Hello p3EE225CF.dip.t-dialin.net [62.226.37.207], pleased to meet you
I made a small program that sends a mail via smtp, if you want, I can send it you. The hard thing was to find out, how to get the server responses and answer correct.
I hope I could help, and sorry for my english!
If you have any additional questions to SMTP, post them!
I didn't understand quite a bit of what you said so, I will be more spicific about what I want, by the way, your English is quite good, no need to be sorry.
My email acount is [email protected]
I want someone to send email to me. he is with Yahoo or Hotmail,
what should I put in the SMPT box. Is the STMP essential?
If I put the code you have kindly send, will it do the job?
I will be glad to receive your program if you don't mind.
Ok, so for sending from any account to a Yahoo account:
On your form you need this:
- TextBox Name = Text1, Multiline = True
- CommandButton Name = Command1, Caption = Send
- Winsock Name = Winsock1, Protocol = 0, LocalPort = 25, RemotePort = 25, RemoteHost = smtp.mail.yahoo.com
Code:
Dim CRLF As String 'You have to end every command with a carrige return
Dim inBuffer As String 'Stores the incoming messages from the server
Dim outBuffer As String 'Stores your messages
Dim cid As Integer 'Command ID, stores the current state of the transaction
Private Function Status(text$)
Text1.text = Text1.text & text$ & CRLF
End Function
Private Sub Form_Load()
CRLF = Chr(13) & Chr(10)
End Sub
Private Sub Command1_Click()
Text1.text = ""
Winsock1.Close
cid = 1
Winsock1.Connect
End Sub
Private Sub Winsock1_Connect()
Status ("Connected!")
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData inBuffer
Select Case cid
Case 0
Status ("*Confirmation")
Status (inBuffer)
Winsock1.SendData "QUIT" & CRLF
cid = 10
Case 10
Status ("*Confirmation")
Status (inBuffer)
cid = 11
Case 1
outBuffer = "HELO Python" & CRLF
If Left(inBuffer, 3) = "220" Then
Status ("*Connected")
Status (inBuffer)
Status ("#Say hello")
Status (outBuffer)
inBuffer = ""
Winsock1.SendData outBuffer
cid = 2
Else
cid = 0
End If
Case 2
outBuffer = "MAIL FROM:<[email protected]>" & CRLF
If Left(inBuffer, 3) = "250" Then
Status ("*Confirmation")
Status (inBuffer)
Status ("#Sender")
Status (outBuffer)
inBuffer = ""
Winsock1.SendData outBuffer
cid = 3
Else
cid = 0
End If
Case 3
outBuffer = "RCPT TO:<[email protected]>" & CRLF
If Left(inBuffer, 3) = "250" Then
Status ("*Confirmation")
Status (inBuffer)
Status ("#Recipient")
Status (outBuffer)
inBuffer = ""
Winsock1.SendData outBuffer
cid = 4
Else
cid = 0
End If
Case 4
outBuffer = "DATA" & CRLF
If Left(inBuffer, 3) = "250" Then
Status ("*Confirmation")
Status (inBuffer)
Status ("#Start sending mail")
Status (outBuffer)
inBuffer = ""
Winsock1.SendData outBuffer
cid = 5
Else
cid = 0
End If
Case 5
outBuffer = "From: " & Chr(34) & "Name of sender" & Chr(34) & " <[email protected]>" & CRLF
outBuffer = outBuffer & "To: " & Chr(34) & "Python" & Chr(34) & " <[email protected]>" & CRLF
outBuffer = outBuffer & "Subject: Blabla" & CRLF
outBuffer = outBuffer & "Content-Type: text/plain; charset=" & Chr(34) & "iso-8859-1" & Chr(34) & CRLF
outBuffer = outBuffer & "MIME-Version: 1.0" & CRLF
outBuffer = outBuffer & "X-Mailer: Script Soft Mailer" & CRLF
outBuffer = outBuffer & "" & CRLF 'First line has to be empty
outBuffer = outBuffer & "Text line 1" & CRLF
outBuffer = outBuffer & "Text line 2" & CRLF
outBuffer = outBuffer & "..." & CRLF
If Left(inBuffer, 3) = "354" Then
Status ("*Startsignal")
Status (inBuffer)
Status ("#Text")
Status (outBuffer)
inBuffer = ""
Winsock1.SendData outBuffer
Winsock1.SendData CRLF & "." & CRLF 'Sign to end mail
cid = 6
Else
cid = 0
End If
Case 6
outBuffer = "QUIT" & CRLF
If Left(inBuffer, 3) = "250" Then
Status ("*Confirmation")
Status (inBuffer)
Status ("#Close connection")
Status (outBuffer)
inBuffer = ""
Winsock1.SendData outBuffer
cid = 7
Else
cid = 0
End If
Case 7
Status ("*Confirmation")
Status (inBuffer)
If Left(inBuffer, 3) = "221" Then
Winsock1.Close
End If
End Select
If cid = 0 Then
Winsock1.SendData "RSET" & CRLF
Status ("!Error! Reset has been sent!")
Status (inBuffer)
End If
I have also uploaded the project, so everone can download it.
It only works if you send from a Yahoo account to an other. This is against spamming. But there are quite a lot of severs that allow you to send a mail from any address to any address. This is often used for anonymous mails (but they aren't really) and for mail bombing .
I love to know how to disguise My IP address but for the time being, it's not important. My friend knows less from computer programming than I do. By the way I am not behind a firewall
Regards
Last edited by Python; May 21st, 2001 at 06:32 AM.
!Error! Reset has been sent!
521 yahoo.com closing transmission channel. You must be pop-authenticated before you can use this smtp server, and you must use your yahoo mail address for the Sender/From field.
If you use [email protected] it's clear:
You can only send mails over the Yahoo server if you have a Yahoo address.
If you use [email protected]:
Yahoo has an anti-spamming mechanism. Before you can send your mail, you have to check your E-Mail with your Yahoo account. Because the SMTP protocol doesn't use a password, Yahoo verifies your IP. The POP3 protocol to check your mail uses a password, and Yahoo saves your IP for a some minutes (I don't know how much, something between 30 - 120 min.). If you send a mail after you have checked your mails, Yahoo knows that you have logged on with your password with your current IP and allows you to send mails over POP3.
Some before you send mails, first check mails.
There is a password function in the SMTP protocol, but I didn't find out how to use it. This is very new and not every mail-client supports it.
If you want to be able to send an email to anybody on any host, you only have to send it to the smtp server of the recipient's host!
This is usualy not the same smtp server that is used by users of this host to send emails.
So, how do you know at which server you must send the message?
You extract the domain name from the email ([email protected] -> hotmail.com)
and then you look up the MX register in the DNS and it will tell you the server name.
For exemple, for yahoo I got mx2.mail.yahoo.com
So I can send an email to [email protected] using this address without logging in before (that normal because how would a server send an email to yahoo otherwise?).
I'm just wondering why softwares like Outlook or Eudora don't have the option to send the message directly to the recipient's server instead of sending it to the user's server, which will then transmit it to the recipient's server...
1) How would I go about looking up the "MX register in the DNS"?
2) Could this look-up be automated so the app does the look-up not the user?
3) Are there any SMTP servers that will accept any e-mail address?
4) Where can I find these?
5) How would I route the "e-mail" through a proxy server?
I would like to add an e-mail function to one of my VB apps, but I don't have much info on what's the best way to do it. I read another post by Aaron Young....where he used MAPI....I think the user would need Outlook installed to use this method....not sure.
What would be the best method for sending "e-mail" with a VB app....Anyone?
I've found some dll or ocx that do the same job, but unlike this one they were not free
2.
sure
just extract the domain name from the email and get the server address.
3.
I'm not sure... because of spamming, they probably won't accept email from someone that is not a user of the server if the recipient of the email is located on another host.
4. Good question
5. I don't know. Someone else can surely answer that.
To send an email, you can modify the code above posted by floppes, and use the OCX to know to which server you must send it.
it's a way to do that, but I'm not sure this is the *best* way.
Dear Krushstone
I tried [email protected] with no luck. I don't know where I went wrong. Your (mx2.mail.yahoo.com) help a lot. Could you please tell me the Hotmail's also?
And Could you help to send attachments?
If you try
address = mx1.server("hotmail.com")
you will know the address to send the email to hotmail, it will look like
mc1.law5.hotmail.com
You can't connect to mx2.mail.yahoo.com to send an email to hotmail. You need to connect to the place where you want to send the email.
In this case it is hotmail.
To know any other addresses, juste download MXcontrol.zip that I attached to a previous message and use the OCX to know them.
address = mx1.server("addresstoknow.com")
Normally, for the DNS, it will the combo box will be filled during the app is loading.
BUT, if you get an error with the OCX, I think that the OCX can't extract your DNS from your registry.
It works fine for me on win2k, and I think this works with 95/98 too.
The DNS server is the DNS server of your ISP where your computer connect to resolve domain name.
In a command prompt in NT4, type
ipconfig /all
you should get 2 dns server(not tested on NT4, only on 2K).
Now that you know these addresses, you could modify the code to use one or the other instead of letting the program extracting it from the registry.
If you want, I can modify the OCX so you can pass the DNS as an argument, so it won't read the registry.
I think that the best would be that the ocx detects if the OS is NT4 and to extract the DNS in an other way so it doesn't crash.
I'll check this out this evening because for the moment I don't have access to a NT4 machine.
Nucleus
Your image in your signature isn't showing up...
is it stored on your HD or the net?
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Yup
...and there it was..Gone!
..if you want to use a pic you have to store it on some site and then reference it...Yahoo...Pictures is a good easy local.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
I finally got it working *whew*, thankyou for helping Krushstone . I agree with you, why doesn't outlook have this sort of functionality built into it?
One last question, the reason I could not send was that I was using the wrong server address. I used the MX lookup exe as your ocx did not work on my machine.
Now when I ran start.com.au though, the results were:
[Preference = 20] mail1.start.com.au
[Preference = 20] mail2.start.com.au
[Preference = 10] maild.startcorp.com
Best MX record to send through : maild.startcorp.com
I tried maild.startcorp.com but it failed (hence my post to you). However, both mail1.start.com.au and mail2.start.com.au worked as SMTP hosts.
Now if mail1.start.com.au is a mailserver, what is maild.startcorp.com, and why does the exe recommend using it?
Can you give the error that you had by trying maild.startcorp.com?
If I knew someone on this host I could try to send him a email.
I tried the OCX on NT4. It extracted the good DNS from the registry.
I didn't have the full access on it, and it wasn't connected to the Internet so I wasn't able to test the resolving of MX record.
Also, I'm getting an error on Win95.
When it will be corrected i'll post a new version of the OCX
It has been tested on Win95 and on Win2K. If it doesn't work on your computer, please tell me the OS version that you're using and I'll try to correct it.
In most of the cases, if it doesn't work it's because it can't extract the DNS from the registry.
So I'd need to know where to go in the registry on this OS to extract the DNS.
There are 2 ways to use the OCX
1. server = MX1.server(name as string)
It will try to extract the DNS from the registry, so maybe it won't work.
2. server = MX1.ServerWithDNS(name as string, dns as string)
The DNS server is an argument. This will be useful if it can't be extracted correctly with the first function. But you need to know the DNS, which can be found with
winipfg on a win9X machine
ipconfig /all on a NT machine (2K included)
I retried it again this morning, and it actually works now.
My guess is that maild.startcorp.com redirects to either mail1.start.com.au or mail2.start.com.au, meaning that if one of the mailservers goes down (say mail1.start.com.au) then the mail is redirected to mail2.start.com.au.
Perhaps there was a technical hitch with maild.startcorp.com at the time I was testing (the mail system has benn playing up recently). Just goes to show that the achillies heel of that system is that if maild.startcorp.com goes down, then mail trying to go through it, doesn't make it to either mail server .