CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Jan 1999
    Posts
    1

    How can I send an Email with VB?



    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!!!!!

  2. #2
    Join Date
    Apr 1999
    Location
    Cambridge University, U.K.
    Posts
    10

    Re: How can I send an Email with VB?



    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

  3. #3
    Join Date
    Jun 1999
    Posts
    11

    Re: How can I send an Email with VB?

    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.


  4. #4
    Join Date
    May 1999
    Posts
    3,332

    Re: How can I send an Email with VB?

    if you clients have MAPI (e.g. Exchange client) you can use the MAPI controls that come with VB (MAPI Session and MAPI message).


  5. #5
    Join Date
    Jul 1999
    Posts
    58

    Re: How can I send an Email with VB?

    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...


  6. #6
    Join Date
    Jun 1999
    Posts
    11

    Re: How can I send an Email with VB?

    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.



  7. #7
    Join Date
    Jul 1999
    Posts
    5

    Re: How can I send an Email with VB?

    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


  8. #8
    Join Date
    Jul 1999
    Posts
    5

    Re: How can I send an Email with VB?

    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.


  9. #9
    Join Date
    Jul 1999
    Posts
    58

    Re: How can I send an Email with VB?

    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....


  10. #10
    Join Date
    Jun 1999
    Posts
    11

    Re: How can I send an Email with VB?

    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
    '[email protected] 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
    '[email protected] 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






  11. #11
    Guest

    Re: How can I send an Email with VB?

    Kindly send me the code to send mail with file attachments using SMTP ASAP.
    my email id is [email protected]. I need this very urgently.
    thanks
    Ali


  12. #12
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: How can I send an Email with VB?

    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

  13. #13
    Join Date
    Apr 1999
    Location
    PARIS, FRANCE
    Posts
    16

    Re: How can I send an Email with VB?

    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
    _/ _/ _/ [email protected]
    _/ _/_/_/

  14. #14
    Join Date
    Mar 2000
    Location
    MALAYSIA
    Posts
    30

    Re: How can I send an Email with VB?

    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 = "[email protected]"
    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.



  15. #15
    Guest

    Please send code

    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.
    [email protected]


Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured