DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Sending mail from VB app

  1. #1
    Jorge Guest

    Sending mail from VB app



    No problem sending a message. The dialog compose mail appears and I can
    send the message or abort it.
    My question is how can I distinguish from sending or aborting?
    The mapimessage control allways return False in the .MsgSent property
    and I know that's not true because I checked that e-mail account and the
    message is there.
    Thanks for any help.

    Jorge

  2. #2
    Join Date
    Feb 2007
    Posts
    9
    Quote Originally Posted by Jorge
    No problem sending a message. The dialog compose mail appears and I can
    send the message or abort it.
    My question is how can I distinguish from sending or aborting?
    The mapimessage control allways return False in the .MsgSent property
    and I know that's not true because I checked that e-mail account and the
    message is there.
    Thanks for any help.

    Jorge
    I have the same prob. And I can not solve too. May be this prob can't be solved????

    Anyone can help?

    this is my code:

    Code:
        'Sign in
        MAPISession1.DownLoadMail = False
        MAPISession1.LogonUI = False
        MAPISession1.SignOn
        MAPIMessages1.MsgIndex = -1
        MAPIMessages1.SessionID = MAPISession1.SessionID
        
        'Compose email
        MAPIMessages1.Compose
        MAPIMessages1.RecipDisplayName = EmailAdress
        MAPIMessages1.MsgSubject = "Example"
        MAPIMessages1.MsgNoteText = "Don't delete this file please"
        MAPIMessages1.AttachmentPathName = ("C:\test.txt")
        MAPIMessages1.ResolveName
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'For testing
        MsgBox (MAPIMessages1.MsgSent) 'false - I think it's correct
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
        MAPIMessages1.Send
    
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'For testing
        MsgBox (MAPIMessages1.MsgSent) 'Always be FALSE ?? WHY?
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        MAPISession1.SignOff
    
        MsgBox (MAPIMessages1.MsgSent) 'FALSE too!!?????
    Help me please!!!

  3. #3
    Join Date
    Jan 2007
    Posts
    11

    Smile Better method

    Hi,

    I suggest that you guys use vbsendmail.dll instead of MAPI.

    I've used it in my applications. It is very easy to use.

    Here is a link:
    http://www.freevbcode.com/ShowCode.Asp?ID=109

    -nakkimake-

  4. #4
    Join Date
    Feb 2007
    Posts
    9
    Hi nakkimake,
    Can I check wheather currently email has been sent to mail server or not with vbsendmail.dll??

  5. #5
    Join Date
    Jan 2007
    Posts
    11

    Thumbs up

    Yes, it should be possible (I don't exactly know which kind of errors it will trap).

    Here's my actual code how I used it (it is mostly the same code as in the developer's example from the link I pasted before). This is just my example code, not official.

    Register the vbsendmail.dll, set a reference to it and paste this code into a form:


    Option Explicit
    Dim WithEvents poSendMail As vbSendMail.clsSendMail
    Attribute poSendMail.VB_VarHelpID = -1
    '
    Public Sub SendMail(ByVal Subject As String, ByVal Message As String, ByVal Recipient As String)
    Set poSendMail = New clsSendMail
    '
    With poSendMail
    '
    ' **************************************************************************
    ' Optional properties for sending email, but these should be set first
    ' if you are going to use them
    ' **************************************************************************
    '
    '.SMTPHostValidation = VALIDATE_HOST_DNS ' Optional, default = VALIDATE_HOST_DNS
    '.EmailAddressValidation = VALIDATE_SYNTAX ' Optional, default = VALIDATE_SYNTAX
    '.Delimiter = ";" ' Optional, default = ";" (semicolon)
    '
    ' **************************************************************************
    ' Basic properties for sending email
    ' **************************************************************************
    '
    .SMTPHost = "SMTP.XXXXXXX.COM" ' Required the fist time, optional thereafter
    .From = "XXXXX.XXXXX@XXXXX.XXX" ' Required the fist time, optional thereafter
    .FromDisplayName = ApplicationName ' Optional, saved after first use
    .Recipient = Recipient ' Required, separate multiple entries with delimiter character
    .RecipientDisplayName = Recipient ' Optional, separate multiple entries with delimiter character
    '.CcRecipient = "" ' Optional, separate multiple entries with delimiter character
    '.CcDisplayName = "" ' Optional, separate multiple entries with delimiter character
    '.BccRecipient = "" ' Optional, separate multiple entries with delimiter character
    '.ReplyToAddress = "" ' Optional, used when different than 'From' address
    .Subject = Subject ' Optional
    .Message = Message ' Optional
    '.Attachment = "" ' Optional, separate multiple entries with delimiter character
    '
    ' **************************************************************************
    ' Additional Optional properties, use as required by your application / environment
    ' **************************************************************************
    '.AsHTML = False ' Optional, default = FALSE, send mail as html or plain text
    '.ContentBase = "" ' Optional, default = Null String, reference base for embedded links
    '.EncodeType = MIME_ENCODE ' Optional, default = MIME_ENCODE
    '.Priority = NORMAL_PRIORITY ' Optional, default = NORMAL_PRIORITY
    '.Receipt = False ' Optional, default = FALSE
    '.UseAuthentication = False ' Optional, default = FALSE
    '.UsePopAuthentication = False ' Optional, default = FALSE
    '.Username = "" ' Optional, default = Null String
    '.Password = "" ' Optional, default = Null String, value is NOT saved
    '.POP3Host = ""
    '.MaxRecipients = 100 ' Optional, default = 100, recipient count before error is raised
    '
    ' **************************************************************************
    ' Advanced Properties, change only if you have a good reason to do so.
    ' **************************************************************************
    '.ConnectTimeout = 10 ' Optional, default = 10
    '.ConnectRetry = 5 ' Optional, default = 5
    '.MessageTimeout = 60 ' Optional, default = 60
    '.PersistentSettings = True ' Optional, default = TRUE
    '.SMTPPort = 25 ' Optional, default = 25
    '
    ' **************************************************************************
    ' OK, all of the properties are set, send the email...
    ' **************************************************************************
    '.Connect ' Optional, use when sending bulk mail
    .Send ' Required
    '.Disconnect ' Optional, use when sending bulk mail
    ' ' MX look up was used to find a host
    End With
    '
    End Sub
    '
    Private Sub poSendMail_SendSuccesful()
    '
    Set poSendMail = Nothing
    MailSendStatus = 1
    Unload Me
    '
    End Sub
    '
    Private Sub poSendMail_SendFailed(Explanation As String)
    '
    frmErrMsgBox.AddErrMsg ("Your attempt to send mail failed for the following reason(s): " & vbCrLf & Explanation)
    Set poSendMail = Nothing
    MailSendStatus = 2
    Unload Me
    '
    End Sub

  6. #6
    Join Date
    Feb 2007
    Posts
    9
    I have tried this code, but my prog didn't work at all. Then I got this mess of error: "Connection is aborted due to timeout or other failure".
    I see in my setting g-mail, there is incoming mail (pop3) property more (value = 995) maybe this vbSendMail.dll is out of date? I can not send email or receive email at all. Help me plz.

    my code:
    Code:
    Private Sub Form_Load()
    Set poSendMail = New clsSendMail
    '
    With poSendMail
    .SMTPHost = "SMTP.gmail.COM" ' Required the fist time, optional thereafter
    .From = "cuongmits@gmail.com" ' Required the fist time, optional thereafter
    .FromDisplayName = "ApplicationName" ' Optional, saved after first use
    .Recipient = "cuongmits@yahoo.com" ' Required, separate multiple entries with delimiter character
    .RecipientDisplayName = "Cuong Yahoo" ' Optional, separate multiple entries with delimiter character
    .Subject = "Subject" ' Optional
    .Message = "Message" ' Optional
    .UseAuthentication = True ' Optional, default = FALSE
    .UsePopAuthentication = True ' Optional, default = FALSE
    .Username = "cuongmits" ' Optional, default = Null String
    .Password = "*******" ' HERE IS MY PASS FIT WITH EMAIL LOGIN NAME
    .POP3Host = "pop.gmail.com"
    .SMTPPort = 465      'WHERE IS INCOMING MAIL (POP3) PROPERTY (VALUE = 995 FOR GMAIL)???
    .Send ' Required
    End With
    '
    End Sub
    Last edited by cuongmits; 02-10-2007 at 02:56 PM.

  7. #7
    Join Date
    Jan 2007
    Posts
    11

    Smile

    Is it possible for you to first get your email sending/receiving to work in a factory's intranet environment? Because that code I sent works directly in our house (only smtp server and sender address needs to be changed).

    I have used that vbsendmail.dll only inside our factory, but surely it should be work also in external emails.

    But it might be easier to test it like that (you know then that your code works).

    That vbsendmail.dll is so far the best email method I've found for VB6.


    -nakkimake-

  8. #8
    Join Date
    Feb 2007
    Posts
    9
    Oh, maybe because of this code line:
    [code]
    Attribute poSendMail.VB_VarHelpID = -1
    [code]
    When I try to compile my prog with this code line, there was mess: compile error: Syntax error; then I delete it, and prog didn't work.
    So how can I do with that code line?
    Is it in the mail code form or in .bas file?
    Thanks so much!

  9. #9
    Join Date
    Feb 2007
    Posts
    9
    Can you send your prog with vbSendEmail.dll, which can works normally to me plz?

  10. #10
    Join Date
    Jan 2007
    Posts
    11

    Smile

    I also just noticed that the codeline you mentioned shouldn't be there. I opened my .frm file with wordpad and just copied a whole code from line "Option Explicit" to bottom to here. But if that code is opened normal way with VB, there's no that codeline. So remove it, and it should then work.

    -nakkimake-

  11. #11
    Join Date
    Feb 2007
    Posts
    9
    Yes, I've tried to compiled my prog without that codeline, but it doesn't work

  12. #12
    Join Date
    Feb 2007
    Posts
    9
    I've tried with CDO too, but I got another prob, RUN-TIME ERROR '-214767259 (80004005)': AUTOMATION ERROR UNSPECIFIED ERROR
    (
    Code:
    Private Sub Command1_Click()
           Dim objSession As MAPI.Session
           Dim objMessage As Object
           Dim objRecipient As Object
    
           'Create the Session Object.
           Set objSession = CreateObject("MAPI.Session")
    ...
    End Sub

  13. #13
    Join Date
    Jan 2007
    Posts
    11

    Smile

    I cannot send my big program where email sending is just a small part of it, but I have also created a little program that allows email sending with that dll.

    I will send it now to you, if I find your email address...

    2 things I will first change inside the code: smtp and sender addresses.


    -nakkimake-

  14. #14
    Join Date
    Feb 2007
    Posts
    9
    cuongmits@gmail.com is my email addr.
    Thanks so much Nakkimake.

  15. #15
    Join Date
    Feb 2007
    Posts
    9
    you missed to send file module1.bas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center