CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 41 of 41
  1. #31
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: sending e-mail through VB application

    The question is 8 years old! I doubt the poster is still searching for a solution.

    Aside from that the answer just posted is not using the correct language so it would not help even if the poster was still looking.
    Always use [code][/code] tags when posting code.

  2. #32
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: sending e-mail through VB application

    AND there are no code tags!

  3. #33
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Smile Re: sending e-mail through VB application


    This works OK- but it sends mail the before the user can enter text into the body. I'd like to bring up Outlook, start an empty Email , fill in the TO: address, subject, and maybe a line of two in the Body, then allow the user to fill in the rest of the body of the message, then send it, after they finish typing it.

    I've looked in the FAQ and the Five Ways to send email- they are variations on yoru method. I can't get the command line completion to work on the objOutlook object, so I cant see the other methods.
    Hi,
    why don't you use vbsendmail.dll .you can send mail without outlook !.Just download the vbsendMail.dll from following web site .and place VbsendMail.dll into system32 folder .
    http://www.freevbcode.com/ShowCode.asp?ID=109.

    step 2.
    just copy vbsendmail.dll it into sytem32 folder .
    step 3
    register this using regsvr32
    step 4
    write the following declaration in the general section of your form .where you want to use this code .
    Code:
    Private WithEvents poSendMail   As vbSendMail.clsSendMail
    Private Function SendMail()
        
        Set poSendMail = New vbSendMail.clsSendMail
        poSendMail.SMTPHost = "SMTP.GMAIL.COM"   'here  smtp server 
        poSendMail.From = "firoz.raj@gmail.com"  'From where y want to send .
        poSendMail.FromDisplayName = "FEEROZE"  
        poSendMail.RecipientDisplayName = "xx;mm" 'Put receipients Name 
        poSendMail.Recipient = ""firoz.raj@gmx.com"[/COLOR]]firoz.raj@gmx.com " 'Type your Receipient name .to whom y want to send 
        poSendMail.CcDisplayName = "Wof;Datamiser;David"  'Write Carbon copy as per your convenience
        poSendMail.CcRecipient = " " ' in this property you can write Recipient Email
        poSendMail.Subject = "Email Demo" 'You can type subject in subject property of PosendMail object.
        poSendMail.message = "please find your attachment "
        poSendMail.Attachment = "C:\Log\" & Attachment FileName
        poSendMail.Send
        Set poSendMail = Nothing
    End Function:wave::wave:
    Last edited by firoz.raj; December 29th, 2011 at 07:00 PM.

  4. #34
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: sending e-mail through VB application

    Once again someone posting to an 8 year old thread, would be nice if people would take the time to look at other posts and perhaps even the date of the post before pulling a long dead thread back to the top of the list.
    Always use [code][/code] tags when posting code.

  5. #35
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: sending e-mail through VB application

    No longer recommended, as too many people had problems. (Or OUTLOOK was changed after Office 2000) Should actually TRY the code, before you post it for others to follow

    AND:
    .SMTPHost = "SMTP.GMAIL.COM" 'here smtp server
    poSendMail.From = "firoz.raj@gmail.com" 'From where y want to send .
    poSendMail.FromDisplayName = "FEEROZE"
    poSendMail.RecipientDisplayName = "xx;mm" 'Put receipients Name
    poSendMail.Recipient = ""firoz.raj@gmx.com"[/color]]firoz.raj@gmx.com " 'Type your Receipient name .to whom y want to send
    poSendMail.CcDisplayName = "Wof;Datamiser;David" 'Write Carbon copy as per your convenience
    poSendMail.
    Should be the last straw...
    Last edited by dglienna; December 29th, 2011 at 10:28 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #36
    Join Date
    Sep 2005
    Location
    Delhi, INDIA
    Posts
    237

    Re: sending e-mail through VB application

    Here is a Simple way to do this, No Outlook required, No win-socket Required.

    Just add this Library to your project and use this function for send emails from VB applications.

    Microsoft CDO for Windows 2000 Library



    Code:
    Public Sub SendEMail(lTo As String, LSubject As String, lAttchCount As Integer, lBody As String, Optional SingalFile As String, Optional lAttchements)
    
        On Error GoTo erh
    
            Dim Correio As CDO.Message
            Set Correio = CreateObject("CDO.Message")
    
            Correio.From = """ABC Org"" <abc@gmail.com>"
            Correio.To = lTo
            Correio.BCC = "jkl@gmail.com, mno@gmail.com"
            Correio.Subject = LSubject
            Correio.TextBody = lBody
                    
            If lAttchCount = 1 Then
                Correio.AddAttachment SingalFile
            End If
            
            Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
            Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
            Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
            Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
            Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "abc@gmail.com"
            Correio.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "abc123"
    Correio.Configuration.Fields.Update
    Correio.Send
        
        Exit Sub
    erh:
    
        MsgBox Err.Description, vbApplicationModal + vbInformation, "My App"
        Exit Sub
    End Sub
    I'M BACK AGAIN !!
    -------------------------------------------------------------------------
    enjoy the VB !
    If any post helps you, please rate that.
    Always try to findout the Solutions, instead just discussing the problem and its scope!

  7. #37
    Join Date
    Jan 2012
    Posts
    1

    Question Re: sending e-mail through VB application

    hello i used below code but still error 530 5.7.0 must issue a STARTTLS command first.

    Code:
    Dim UserName$, UserMail$, MailRecipiant$, MailBody$, SockData$
    
    Private Sub Command1_Click()
    UserName = "leonscott136@gmail.com"
    UserMail = "leonscott136<leonscott136@gmail.com>"
    MailRecipiant = UserMail
    MailBody = "The message goes here"
    Winsock1.LocalPort = 0
    Winsock1.RemoteHost = "smtp.gmail.com"
    Winsock1.RemotePort = 587
    Winsock1.Connect
    End Sub
    
    Private Sub Winsock1_Connect()
    Label1 = "Sending message..."
    Winsock1.SendData "EHLO " & UserName & vbCrLf
    If Not WaitFor("250") Then GoTo 100
    Winsock1.SendData "MAIL FROM: " & UserMail & vbCrLf
    If Not WaitFor("250") Then GoTo 100
    Winsock1.SendData "RCPT TO: " & MailRecipiant & vbCrLf
    If Not WaitFor("250") Then GoTo 100
    Winsock1.SendData "DATA" & vbCrLf
    If Not WaitFor("354") Then GoTo 100
    Winsock1.SendData MailBody & vbCrLf & "." & vbCrLf
    If Not WaitFor("250") Then GoTo 100
    Winsock1.SendData "QUIT" & vbCrLf
    If Not WaitFor("221") Then GoTo 100
    Label1 = "Message sent"
    GoTo 200
    100
    Label1 = SockData
    200
    Winsock1.Close
    End Sub
    
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Winsock1.GetData SockData
    End Sub
    
    Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    Label1 = "Error: " & Description
    SockData = "Error"
    Winsock1.Close
    End Sub
    
    Private Function WaitFor(SockResponse As String) As Boolean
    Do While Left(SockData, 3) <> SockResponse And Left(SockData, 3) <> "220" And Left(SockData, 3) <> "250"
      DoEvents
      If Left(SockData, 3) > "400" Then Exit Function
    Loop
    WaitFor = 1
    SockData = ""
    End Function
    iam trying to send mail to gmail anybody tell me what i put wrong above code
    Last edited by WizBang; January 20th, 2012 at 11:29 PM. Reason: Added [code] tags

  8. #38
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: sending e-mail through VB application

    You should describe in more detail what happens or what happens NOT.

    Have you verified that a connection to smtp.gmail.com has been established?

  9. #39
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: sending e-mail through VB application

    Quote Originally Posted by leonscott136 View Post
    hello i used below code but still error 530 5.7.0 must issue a STARTTLS command first.
    Also, IIRC this error message does not necessarily mean your SMTP implementation is faulty. (I didn't closely examine your code though, one of the reasons being that it's pretty hard to read without the code tags.) It may just mean that the server you're connecting to requires you to use TLS but your SMTP implementation doesn't support that.

    I have no experience with smtp.gmail.com, so I don't know whether that should work without TLS. I suggest you run a test with a server of which you know for sure that it doesn't require TLS. I'm afraid though that, in case that actually is the problem, implementing the entire TLS protocol yourself in VB6 would be a lot of work...

    HTH
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  10. #40
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: sending e-mail through VB application

    This thread is too old to keep repeating the same thing...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #41
    Join Date
    Dec 2001
    Posts
    6,332

    Re: sending e-mail through VB application

    @leonscott136:
    That Winsock code looks a lot like what I've posted in the past. I believe it fails because gmail requires a secure connection (causing the TLS related error). This document details what needs to be done: https://tools.ietf.org/html/rfc3207

    Whether you'd be able to fulfill the requirements using only Winsock is another matter. It may work with some servers and not others. I've not pursued it, but I suspect it'd require more work than it's probably worth.
    Last edited by WizBang; January 20th, 2012 at 11:51 PM.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

Page 3 of 3 FirstFirst 123

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