Click to See Complete Forum and Search --> : How can I send an Email with VB?


Wanderson
January 2nd, 1999, 03:52 PM
Hello people,

I'm from Brazil, and my English it's too bad!

If you can understand me, then answer my question Please!!!!

How can I send an Email with VB???

Need I use a API? What???


Thanks!!!!!

George
January 12th, 1999, 05:47 PM
Friend:


It will be a long story.


You need use messaging api plus you must install outlook or exchange.


check the vb help to find more information.


hope this help


George

CraigF
July 21st, 1999, 03:44 PM
Hi,

If you are mailing to a POP/SMTP server, then it is a simple straight forward process.

You need to use MS Winsock.ocx and then all you need to do is create a TCP/IP connection to your POP server, then use the SendData command to send information to the server.

You do need to understand SMTP, which is simple, and then as long as you know what to send, there is not a lot of code required, and you do not need outlook, or exchange, just a SMTP compliant server.

If you would like me to tell you the code, reply to this post, and I will get back to you.


Craig.

Lothar Haensler
July 22nd, 1999, 01:47 AM
if you clients have MAPI (e.g. Exchange client) you can use the MAPI controls that come with VB (MAPI Session and MAPI message).

shvonne
July 22nd, 1999, 02:11 AM
hai craig...

i'm shvonne from malaysia. i dunno how to send mail through VB. as u said, if i want to send mail using Winsock.ocx, i need some code. so can u please sends me the code???

so do u know how to send mail using microsoft MAPI controls??? what's the alternative way to send mail in VB??

thanks...

CraigF
July 22nd, 1999, 01:25 PM
Hi shvonne,

Bear with me for a day or so - I have recently written a SMTP client at work, so I will email you the code shortly.

The alternative ways to send mail with VB is to use MAPI as you stated, but this requires Microsoft Exchange servers, which does limit your audience somewhat.

You can use VB to send mail if the user has outlook installed, by creating a new outlook mail object. This code is more difficult to write than SMTP, and obviously requires Outlook to be on the users system.

An example of the SMTP code would be...

Me.winsock1.conntect 172.21.1.5:21
Me.winsock1.senddata "Helo"
Waitloop
Me.winsock1.senddata "MAILFROM: " & sender
waitloop
Me.winsock1.senddata "MAILTO: " & mailto

As you can see, it is quite simple. I will get u the real code as soon as possible. The above uses a WaitLoop procedure, which allws the SMTP server to complete the process before you send more information to it. I will tell you how to do this too.

Regards,
Craig.

Vrajesh Mehta
July 23rd, 1999, 04:43 PM
I would like to know how do we send email on POP3 server using Winsock and Tcp/Ip Can you let me know thw coding

jtsj
July 25th, 1999, 05:07 PM
hie craig did u work out that emailvia tcpip /smtp.would be handy for me too.i had done the same thing using mn outlook was quite simple and workd too , but as said it is limiting coz not all users will have outlook.how is it done via ms exchange?? pl reply to my email id.

shvonne
July 25th, 1999, 09:09 PM
hai jtsj...

what do u mean by the user have to install outlook first? the user that u mention is the person who develop VB application or the recipient?

thanks....

CraigF
July 28th, 1999, 03:05 PM
Sorry for the delay - here is the source code that i have used.

It works with Winsock (SP2)

Windows API/Global Declarations:
Note:This code is formatted to be pasted directly into VB.
Pasting it into other editors may or may not work.



'***************************************************************
'Windows API/Global Declarations for :SMTP32.ocx
'***************************************************************
'None



Source Code:
Note:This code is formatted to be pasted directly into VB.
Pasting it into other editors may or may not work.



'***************************************************************
' Name: SMTP32.ocx
' Description:This control demonstrates how to send mail using th
' e Microsoft Winsock Control 5.0(SP2)
' By: Bruce Smith
'
'
' Inputs:'txtServer smtp.mailserver.com
'szEmailFromyourname@bus.com the persons email address thats send
' ing the mail
'szNameFromJohn Doe Your real name or even your alias
'szEmailTo recieving~party@their~pop.net Person your sending an e
' -mail to
'szNameTo Annie Doe reciever's name.
'szSubject This will show as the subject in the message.
'szMsg This is ofcourse the place you put you message.
'
' Returns:Public Event Status(txtStatus As String)
This is the return information from the SMTP server
'
'Assumes:First create a new project select ActiveX control add al
' l the code to it and drop a Microsoft Winsock Control 5.0(SP2) on
' the control. There is only one method its SendBrainDead(txtServer
' As String, szEmailFrom As String, szNameFrom As String, szEmailTo
' As String, szNameTo As String, szSubject As String, szMsg As Stri
' ng) Call it and send it what it expects. It will return info from
' the SMTP server using Public Event Status(txtStatus As String). G
' ood luck.

'
'Side Effects:There is no Error protection but it shouldn'd be to
' hard to implement
'
'Code provided by Planet Source Code(tm) (http://www.Planet-Sourc
' e-Code.com) 'as is', without warranties as to performance, fitnes
' s, merchantability,and any other warranty (whether expressed or i
' mplied).
'This code is for personal private or personal business use only
' and may not be redistributed or duplicated in any format without
' express written consent from Planet Source Code or Exhedra Soluti
' ons, Inc.
'***************************************************************

Option Explicit
'Created by Jax-HM Your OCX HackMan
'Use for free, as is ,Learn something from it
'Share you code with the world
Private nConnected As Boolean
Private WithEvents Winsock1 As Winsock
Private ptRetCode As Boolean
Public Event Status(txtStatus As String)


Sub SendBrainDead(txtServer As String, szEmailFrom As String, szNameFrom As String, szEmailTo As String, szNameTo As String, szSubject As String, szMsg As String)


'txtServer smtp.mailserver.com
'szEmailFromyourname@bus.com the persons email address thats send
' ing the email
'szNameFromJohn Doe Your real name or even your alias
'szEmailTo recieving~party@their~pop.net Person your sending an e
' -mail to
'szNameTo Annie Doe reciever's name.
'szSubject This will show as the subject in the message.
'szMsg This is ofcourse the place you put you message.
'NOTE: I do not do any MIME or BASE64 in this code if someone cre
' ates an OCX for this
'i'd love a copy.
'-- This routine sends an email message via an SMTP gateway.


If Not nConnected Then 'Check to see if its a used control
InitIt txtServer
End If

Dim szCRLF As String
Dim szCompleteMsg As String
'-- All lines end with a CR/LF Pair
szCRLF = Chr$(13) & Chr$(10)
'-- Construct the data as a 4-line header (Date, From,
'To, and Subject) followed by the message text
szCompleteMsg = "DATE: " & Format$(Now, "dd mmm yy ttttt") & szCRLF
szCompleteMsg = szCompleteMsg & "FROM: " & szNameFrom & szCRLF
szCompleteMsg = szCompleteMsg & "TO: " & szNameTo & szCRLF
szCompleteMsg = szCompleteMsg & "SUBJECT: " & szSubject & szCRLF & szCRLF
szCompleteMsg = szCompleteMsg & szMsg & szCRLF
'-- Wait for a response,don't just send blindly
Winsock1.SendData "HELO " & Winsock1.LocalHostName & szCRLF
WaitLoop
Winsock1.SendData "MAIL FROM: <" & szEmailFrom & ">" & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData "RCPT TO: <" & szEmailTo & ">" & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData "DATA" & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData szCompleteMsg & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
Winsock1.SendData "." & szCRLF
WaitLoop 'This will allow the SMTP server time to process your request
'Clean up the control
Winsock1.SendData "QUIT" & szCRLF
Winsock1.Close
Winsock1.RemotePort = 0
Winsock1.LocalPort = 0
Set Winsock1 = Nothing
nConnected = False
End Sub



Private Sub Winsock1_Connect()

nConnected = True
End Sub



Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

Dim strRet As String
Winsock1.GetData strRet, vbString, bytesTotal
RaiseEvent Status(strRet)
ptRetCode = True
End Sub



Private Sub InitIt(txtServer As String)

'-- Temporarily disable the button
Set Winsock1 = Winsock1
Screen.MousePointer = vbHourglass
'btnSend.Enabled = False
'-- SMTP uses port 25
Winsock1.RemotePort = 25
Winsock1.RemoteHost = txtServer
'-- Try to connect
nConnected = False
'On Error Resume Next
Winsock1.Connect


Do


DoEvents
Loop Until nConnected

Screen.MousePointer = vbNormal
End Sub



Private Sub WaitLoop()

'Wait for a return
'I DONT check return values
'You should do some error protection.


Do Until ptRetCode = True


DoEvents
Loop

ptRetCode = False
End Sub

January 21st, 2000, 04:52 AM
Kindly send me the code to send mail with file attachments using SMTP ASAP.
my email id is shirazi_ar@cmr.satyam.com. I need this very urgently.
thanks
Ali

Chris Eastwood
January 21st, 2000, 09:37 AM
I've just found this on the net - looks well written and very detailed :

http://www.vbip.com/winsock/winsock_uucode_01.asp


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

pgrenette
March 1st, 2000, 04:12 AM
Hi you all,

Everybody wants to send mail and that's OK.
But, did anybody know how to DOWNLOAD mails from a pop3 account ? Hu ?

Tx for any help,
Pierre

_/_/_/ _/_/_/ Pierre Grenette
_/ _/_/
_/_/_/ _/ _/_/ K-Mobile
_/ _/ _/ p.grenette@k-mobile.com
_/ _/_/_/

wenyen
March 29th, 2000, 11:32 PM
I'm using this, but have little problem:

I am writing an email/fax application using the VB MAPI control. And the code is basically like this:

MAPISession.SignOn
MAPISession.NewSession = True

MAPIMessages.SessionID = MAPISession.SessionID

MAPIMessages.Compose
MAPIMessages.MsgIndex = -1
MAPIMessages.RecipAddress = "xxx@xxxx.xx"
MAPIMessages.MsgSubject = "xxxxx"

MAPIMessages.AttachmentIndex = 0
MAPIMessages.AttachmentType = mapData
MAPIMessages.AttachmentPathName = "c:/test.txt"

MAPIMessages.Send

I have both Microsoft Outlook and Outlook Express on my machine. Everything looked pretty good as I was able to get my application to work with Outlook Express, but it fails when using Microsoft Outlook.

The error occurs on the line:
MAPIMessages.Send
and I get the following message:
"Unspecified Error Occurred 32002"

Is there any known problems using the MAPI control with Microsoft Outlook? Any information on this??

Thanks in advance.

June 1st, 2000, 11:05 AM
It would be great if you sent me a sample of the code along with any references and componanats that I would need to add.
imcosmokramer@hotmail.com

Danny Tan
August 7th, 2000, 04:41 PM
Hi Craig,
I read your post regarding this sending mail with SMTP in VB. The code works well if only one recipient. What should I change in SendData method if I need to send a single mail to multiple recipient?

Thanks for any help.
Danny