Results 1 to 31 of 31

Thread: How to send E-Mail with VB6

  1. #1

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    How to send E-Mail with VB6

    Can someone explain to me how can i send e mail to a single address written in a textbox.

    I found this example but it doesnt work for me. I get an error saying Object required. What do i need to do. Could someone please write the whole code to send an e-mail massage (with all assignments and declarations). I dont know what class must i assign to object to work with following commands .

    Code:
    MAPISession1.SignOn
    MAPIMessages1.SessionID = MAPISession1.SessionID
    'Compose new message
    MAPIMessages1.Compose
    'Address message
    MAPIMessages1.RecipDisplayName = "Name"
    MAPIMessages1.RecipAddress = [email protected]
    ' Resolve recipient name
    MAPIMessages1.AddressResolveUI = True
    MAPIMessages1.ResolveName
    'Create the message
    MAPIMessages1.MsgSubject = "Subject"
    MAPIMessages1.MsgNoteText = "Message text"
    'Add attachment
    MAPIMessages1.AttachmentPathName = "file path"
    'Send the message
    MAPIMessages1.Send False
    MAPISession1.SignOff
    For example, i want when i click on button (Command1) to send an e mail to a certain address. Do i need SMTP Host address and if i do, i would need address that i can use. I would be grateful if someone can provide an SMTP adress too .

  2. #2
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: How to send E-Mail with VB6

    SMTP host is the server address used by your internet service provider.
    You can contact your internet service provider for this detail.

    You need to add MAPI OCX by going to reference window..

    Ashish

  3. #3

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Quote Originally Posted by ashishprem
    SMTP host is the server address used by your internet service provider.
    You can contact your internet service provider for this detail.

    You need to add MAPI OCX by going to reference window..

    Ashish

    But in this code above there isnt a command to add SMTP host. Btw, i cant find MAPI OCX. Im looking in Project->References.

    How can i add it?

  4. #4
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: How to send E-Mail with VB6

    you can go in references and then select browse and select this OCX file...MSMAPI32.OCX
    probably it should be in windows\system32 folder.

    Regarding the uasge SMTP details in MAPI code. i believe it uses the outlook configured SMTP..

  5. #5
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: How to send E-Mail with VB6

    you need to assign the outlook profile name in the code

  6. #6
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: How to send E-Mail with VB6

    when i googled i found one sample... it might helps..
    http://www.devarticles.com/c/a/Visua...isual-Basic/2/

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to send E-Mail with VB6

    to use Mapi you need to have a mapi compliant email client such as outlook installed, outlook express is not suitable

    there are several ways to send emails, one of the best is vbsendmail, or you can try cdo like this
    vb Code:
    1. Set objEmail = CreateObject("CDO.Message")
    2. objEmail.From = "your email here"
    3. objEmail.To = text1.text
    4. objEmail.Subject = "subject of email"
    5. objEmail.Textbody = "a message to send"
    6. objEmail.Send
    this may work directly as it will try to use your default settings, otherwise you may need to set the configuation for the cdo object, see this post http://www.vbforums.com/showpost.php...08&postcount=8
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: How to send E-Mail with VB6

    i will go with westconn. vbsendmail is the best.

  9. #9

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Thanks guys. Ill try it now

  10. #10

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    I doesnt work for me. I think i must configure it as you said.
    Well, i have my mail via Yahoo. mail.yahoo.com.
    Can this solution still work for me?

    Code:
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    
    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"
    
    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
    
    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"
    
    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
    
    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    
    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
    
    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    
    objMessage.Configuration.Fields.Update
    
    '==End remote SMTP server configuration section==
    
    objMessage.Send
    Ive red this code you provided. What type of object must i create for this?

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to send E-Mail with VB6

    same object as you create to send the email, just they call it objectmessage in this example

    as i don't need to configure it to work from here i don't have much experience with this side of it, but if you are going to use on other machines it will always be necessary to configure
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: How to send E-Mail with VB6

    I have attached the vbsendmail email application. It works perfectly for me.
    May be you can also make use of it.

    Ashish
    Last edited by ashishprem; Mar 24th, 2008 at 06:09 AM.

  13. #13

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Thank you guys!

  14. #14

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    I get an error saying:

    The message could not be sent to SMTP server. The transport error code was 0x800ccc67. The server response was 421 cannot connect to SMTP server 'here goes IP adress', connect error 10060

  15. #15

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    I fixed that but now i get "530 Authentication required"

  16. #16
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to send E-Mail with VB6

    try to set pop authentication on
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  17. #17
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: How to send E-Mail with VB6

    are you trying with vbsendmail or MAPI component?

    Ashish

  18. #18
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: How to send E-Mail with VB6

    you need to provide the authentication to the SMTP server if you have any.

    Ashish

  19. #19

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Quote Originally Posted by ashishprem
    are you trying with vbsendmail or MAPI component?

    Ashish
    im trying with vbsendmail

    This is my code:

    Code:
    Private Sub Command1_Click()
    
        Set objMessage = CreateObject("CDO.Message")
         
          objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    
    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.mail.yahoo.com"
    
    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    
    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyUserName"
    
    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MyPassword"
    
    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
    
    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    
    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    
    objMessage.Configuration.Fields.Update
    
    '==End remote SMTP server configuration section==
    
        
          objMessage.From = "[email protected]"
     
          objMessage.To = "SomeEMailAdress"
      
          objMessage.Subject = "Test1"
       
          objMessage.Textbody = "Hello"
          
          'objMessage.AddAttachment ""
       
          objMessage.Send
    
    End Sub

    And I get this error:



    Edit:
    I dont use any kind of E-Mail software. I have my mail on Yahoo and i access it from my internet explorer.


    I have changed this value from 0 to 1 and i get error saying:
    Code:
    'value i cahanged
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    Last edited by Dungeon Keeper; Mar 24th, 2008 at 06:45 AM.

  20. #20
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to send E-Mail with VB6

    even if you don't have an email client on your machine you can send smtp email as long as you have an smtp server you can connect to most isp provide a smtp server, but you will need to get the settings for it. the code you are posting in the post above is for cdo message object not vbsendmail, they are dfferent, though proably work much the same underneath. either one needs to connect to smtp server, with the correct settings

    vbsendmail comes with good instructions, and examples for use and has setting for pop authentication, which is often used
    465 seems a strange port for a smtp server, the default setting is 25
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  21. #21
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: How to send E-Mail with VB6

    from your code I can see that you trying to connect to yahoo SMTP server. Is it something that you are under yahoo service provider? The SMTP server will be the server details of your internet service provider.

    Ashish

  22. #22

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Quote Originally Posted by westconn1
    even if you don't have an email client on your machine you can send smtp email as long as you have an smtp server you can connect to most isp provide a smtp server, but you will need to get the settings for it. the code you are posting in the post above is for cdo message object not vbsendmail, they are dfferent, though proably work much the same underneath. either one needs to connect to smtp server, with the correct settings

    vbsendmail comes with good instructions, and examples for use and has setting for pop authentication, which is often used
    465 seems a strange port for a smtp server, the default setting is 25
    I found that port setting via google. Ill try to work with vbsendmail now

    I tried with vbsendmail too and i get same error. authentication required

  23. #23

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Quote Originally Posted by ashishprem
    from your code I can see that you trying to connect to yahoo SMTP server. Is it something that you are under yahoo service provider? The SMTP server will be the server details of your internet service provider.

    Ashish
    Im not under Yahoo but im trying to send mail via yahoo.

    So i cannot send mail via Yahoo if im under diffrent internet provider? I have my email address on Yahoo, i never used E-Mail provided by my provider .

  24. #24

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Ok, lets start from the beginning.

    Ill adjust my mail settings in Outlook. After its done and i can send mail with Outlook what would i need to send mail from VB6.

    Would this work?

    Code:
    MAPISession1.SignOn
    MAPIMessages1.SessionID = MAPISession1.SessionID
    'Compose new message
    MAPIMessages1.Compose
    'Address message
    MAPIMessages1.RecipDisplayName = "Name"
    MAPIMessages1.RecipAddress = [email protected]
    ' Resolve recipient name
    MAPIMessages1.AddressResolveUI = True
    MAPIMessages1.ResolveName
    'Create the message
    MAPIMessages1.MsgSubject = "Subject"
    MAPIMessages1.MsgNoteText = "Message text"
    'Add attachment
    MAPIMessages1.AttachmentPathName = "file path"
    'Send the message
    MAPIMessages1.Send False
    MAPISession1.SignOff

  25. #25
    Member
    Join Date
    Dec 2007
    Posts
    45

    Re: How to send E-Mail with VB6

    Quote Originally Posted by Dungeon Keeper
    Im not under Yahoo but im trying to send mail via yahoo.

    So i cannot send mail via Yahoo if im under diffrent internet provider? I have my email address on Yahoo, i never used E-Mail provided by my provider .

    no need to use email id provided by service provider.
    Once again:
    when you execute the vbsendmail application you need to provide the service provider SMTP details. Not of yahoo SMTP.

    And it doesn't matter whether your sender is yahoo or any other email server.
    You need to provide the authentication if you have any to your SMTP server

  26. #26

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Oh that, I understand now. Than this can work for me if i am using CDO.message?

  27. #27

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Doesnt work. i still get same errors.

  28. #28

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    I get an error when trying to add MSMAPI32.OCX saying "name conflicts with existing project, module or object library."

  29. #29

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Finally I succeeded using MAPI components. Well, i got another question. How is it possible to send to multiple recipients. I dont know, to people from my address book, or to a list of e-mails from a txt document, listbox or something like that.
    Is there any way to avoid that annoying Outlook message saying "Program is attempting to send following message on your behalf" with options "Send" and "Do not send".

  30. #30
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to send E-Mail with VB6

    Is there any way to avoid that annoying Outlook message saying "Program is attempting to send following message on your behalf" with options "Send" and "Do not send".
    do a search, i saw it in a thread at the weekend
    you have to use the add method to add recipients, look at the mapi help, i posted some of that in a thread last week
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  31. #31

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: How to send E-Mail with VB6

    Thanx

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