Announcement

Collapse
No announcement yet.

gbSendMail - Send Emails (Discussion)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • gbSendMail - Send Emails (Discussion)

    This thread is for discussion of my latest posted application, gbSendMail, a very simple client for sending emails.

    gbSendMail additionally provides a test bed for evaluating some of the email options available to PowerBASIC applications. Currently, the public domain Blat and the custom TCP code posted by Wayne Diamond are included in gbSendMail. I also plan to add Paul Squires posted email class.

    If you saw gbBlat, then you'll recognize that gbSendMail is a similar app (same icon), but new features:
    - code structured to allow addition of multiple email solutions/authors
    - two send mail code solutions (Blat and Diamond)
    - support of "John Doe <[email protected]>" address formatting
    - multi-line body support
    - history list that also acts as a minimum feature contact list
    - user-defined values for all visible settings.



    As always, suggestions are welcome!

  • #2
    My thanks go out to Wayne Diamond, who has been very generous with his time in creating his SMTP and ESMTP code/posts. As he updates his code/posts, as I know he's doing even as I type this in, I'll update gbSendMail to keep in sync with his posts.

    Comment


    • #3
      If you'll recall, the whole reason for my recent interest in SMTP code is because I wanted to send my forum PMs to my home email address - allowing me to see my PM and emails together in one place - Outlook.

      With the code in gbSendMail, I now know two ways to do that. Cool beans!

      I'll try to post an update to gbForumMail that adds the "Send as Email" option. I've no doubt that many of you have been just waiting for the opportunity to perform that task! :laugh:

      Ok, actually, no one has ever asked me for that capability. But now that I talk about it, doesn't it sound like a useful think to do? And with the Blat and Diamond send email solutions, nothing stands in our way! Yippee!

      (Is this how a party of 1 sounds? )

      Comment


      • #4
        Another way:

        Code:
        ' ########################################################################################
        ' CDO - Sending a text email with an attached file.
        ' ########################################################################################
        
        #COMPILE EXE
        #DIM ALL
        #INCLUDE ONCE "CDOSYS.INC"
        #INCLUDE ONCE "OLE2UTILS.INC"
        
        ' ========================================================================================
        ' Main
        ' ========================================================================================
        FUNCTION PBMAIN () AS LONG
        
           LOCAL pMessage AS CDO_IMessage
           LOCAL iConf AS CDO_IConfiguration
           LOCAL Flds AS ADOFields
        
           ' // Create an instance of the CDO Message interface
           pMessage = NEWCOM("CDO.Message")
           IF ISNOTHING(pMessage) THEN EXIT FUNCTION
           iConf = NEWCOM "CDO.Configuration"
           IF ISNOTHING(iConf) THEN EXIT FUNCTION
        
           TRY
              ' // Configuration
              Flds = iConf.Fields
              LOCAL schema AS STRING
              schema = "http://schemas.microsoft.com/cdo/configuration/"
              Flds.Item(schema & "sendusing").Value = %CdoSendUsingPort
              Flds.Item(schema & "smtpserver").Value = "smtp.xxxxxxxx" <-- change me
              Flds.Item(schema & "smtpserverport").Value = 25
              Flds.Item(schema & "smtpauthenticate").Value = 1
              Flds.Item(schema & "sendusername").Value = "xxxxxxxxxxxx" <-- change me
              Flds.Item(schema & "sendpassword").Value =  "xxxxxxx" <-- change me
              Flds.Item(schema & "smtpusessl").Value = 1
              Flds.Update
              ' // Recipient name --> change as needed
              pMessage.To = "xxxxxxxxxxx"
              ' // Sender name --> change as needed
              pMessage.From = "xxxxxxxxxxx"
              ' // Subject --> change as needed
              pMessage.Subject = "This is a sample subject"
              ' // Text body --> change as needed
              pMessage.TextBody = "This is a sample message text"
              ' // Add the attachment (use absolute paths).
              ' // Note  By repeating the call you can attach more than one file.
              pMessage.AddAttachment "<full path of the file to attach>"
              ' // Set the configuration
              pMessage.Configuration = iConf
              ' // Send the message
              pMessage.Send
              MSGBOX "Message sent"
           CATCH
              ' // Display the error message
              OleShowErrorInfo OBJRESULT
           FINALLY
              ' // Release the Message object
              pMessage = NOTHING
           END TRY
        
        END FUNCTION
        ' ========================================================================================
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          Hi Jose!
          I thought I'd remembered seeing some code of yours, but hadn't searched it out yet. Thanks for the code/post!

          What formats must I use on the .To and .From properties? Can they have a name and an email address in them? Neither of these seem to work ...

          Code:
                ' // Recipient name --> change as needed
                pMessage.To = "Gary Beene <[email protected]>"
                ' // Sender name --> change as needed
                pMessage.From = "John Doe <[email protected]>"
          Any other formatting/content nuances that I need to know?

          Comment


          • #6
            Jose,
            Sorry, my post didn't give enough information, perhaps.

            These settings are what failed. I tried a few variations on the To/From values but no success:.
            The transport failed to connect to the server.
            My test code ...
            Code:
            #Compile Exe
            #Dim All
            #Include Once "CDOSYS.INC"
            #Include Once "OLE2UTILS.INC"
            Function PBMain () As Long
               Local pMessage As CDO_IMessage, iConf As CDO_IConfiguration, Flds As ADOFields
               pMessage = NewCom("CDO.Message")     ' // Create an instance of the CDO Message interface
               If IsNothing(pMessage) Then Exit Function
               iConf = NewCom "CDO.Configuration"
               If IsNothing(iConf) Then Exit Function
               Try
                  ' // Configuration
                  Flds = iConf.Fields
                  Local schema As String
                  schema = "http://schemas.microsoft.com/cdo/configuration/"
                  Flds.Item(schema & "sendusing").Value = %CdoSendUsingPort
                  Flds.Item(schema & "smtpserver").Value = "smtp.airmail.net" '<-- change me
                  Flds.Item(schema & "smtpserverport").Value = 587
                  Flds.Item(schema & "smtpauthenticate").Value = 1
                  Flds.Item(schema & "sendusername").Value = "[email protected]" '<-- change me
                  Flds.Item(schema & "sendpassword").Value =  "xxxxxxxxxxx" '<-- change me
                  Flds.Item(schema & "smtpusessl").Value = 1
                  Flds.Update
                  pMessage.To       = "[email protected]"
                  pMessage.From     = "[email protected]"
                  pMessage.Subject  = "Jose: This is a sample subject"
                  pMessage.TextBody = "This is a sample message text"
            '      pMessage.AddAttachment "<full path of the file to attach>"
                  pMessage.Configuration = iConf
                  pMessage.Send
                  MsgBox "Message sent"
               Catch
                  OleShowErrorInfo ObjResult      ' // Display the error message
               Finally
                  pMessage = Nothing              ' // Release the Message object
               End Try
            End Function
            ... reformatted the code to make it easier to see what I did ...
            Last edited by Gary Beene; 6 Aug 2014, 12:32 AM. Reason: modified code to see more easily

            Comment


            • #7
              Don't know why you have removed the TRY/CATCH/END TRY block. If there is an error, OleShowErrorInfo OBJRESULT will display error information.
              Forum: http://www.jose.it-berater.org/smfforum/index.php

              Comment


              • #8
                Sorry, Jose,
                I had just posted a piece of the code for brevity.

                I've gone back and put in the entire sample I used. It has the Try/Catch/End Try in it. The error message I got is also given in the post.

                Comment


                • #9
                  Jose, the error I got ...

                  Comment


                  • #10
                    Jose's code looks pretty sweet btw - complete with SSL layer support (albeit reliant on MS system components)
                    Not sure why you're getting that connection error though ... or perhaps it is because you've got SSL = 1 turned on?
                    Code:
                    Flds.Item(schema & "smtpusessl").Value = 1
                    Last edited by Wayne Diamond; 6 Aug 2014, 12:51 AM.
                    -

                    Comment


                    • #11
                      Wayne!
                      Yep, that was it. With SSL=0, it works great.

                      When I read the "smtpusessl" in Jose's code, I'm afraid that I didn't catch that SSL was buried in the term.

                      It would be too embarassing to say what words I tried to make out of the character sequence!

                      Yes, very sweet, Jose!

                      Comment


                      • #12
                        Well,
                        Yes, now that you point it out, I can see it ...

                        smtpusessl = smtp_use_ssl

                        But that's nothing like what my "it's-midnight-brain" tried to get out of it.

                        Comment


                        • #13
                          yeah it does have that "smtpuseless = 1" kinda vibe to it
                          -

                          Comment


                          • #14
                            Not useless because I need it. It is a matter of reading the documentation and seeing what you need or not.

                            This are the list of available configuration fields:

                            autopromotebodyparts
                            flushbuffersonwrite
                            httpcookies
                            languagecode
                            nntpaccountname
                            nntpauthenticate
                            nntpconnectiontimeout
                            nntpserver
                            nntpserverpickupdirectory
                            nntpserverport
                            nntpusessl
                            postemailaddress
                            postpassword
                            postusername
                            postuserreplyemailaddress
                            postusing
                            sendemailaddress
                            sendpassword
                            sendusername
                            senduserreplyemailaddress
                            sendusing
                            smtpaccountname
                            smtpauthenticate
                            smtpconnectiontimeout
                            smtpserver
                            smtpserverpickupdirectory
                            smtpserverport
                            smtpusessl
                            urlgetlatestversion
                            urlproxyserver
                            urlproxybypass
                            usemessageresponsetext
                            Forum: http://www.jose.it-berater.org/smfforum/index.php

                            Comment


                            • #15
                              I was just joking mate
                              -

                              Comment


                              • #16
                                Jose,
                                Thanks again for the post. I almost integrated your code into gbSendMail last night but the rack monster dragged me into his lair before I could finish. I'll have it done today.

                                And yes, Wayne,
                                I took it as the joke you meant - tired eyes not being able to find the valid content in the string!

                                Comment


                                • #17
                                  gbSendMail v1.1 is now available for download.

                                  New Features:
                                  1. Added CDO code approach by Jose Roca (with 2 unique settings, Authenticate and UseSSL)
                                  2. Improved the email History List. Added checkboxes to line items, plus context menus to Check All, UnCheck All, Remove All Checked
                                  3. Changed opening Statusbar content to show the current sendmail code being used
                                  4. Added information to dialog displayed when Settings is pressed.

                                  As always, suggestions/comments are welcome.

                                  Comment


                                  • #18
                                    At this point, there are 10 common pieces of information you can enter on the main screen of gbSendMail:
                                    1. ToName
                                    2. ToAddress
                                    3. FromName
                                    4. FromAddress
                                    5. Server
                                    6. Port
                                    7. User
                                    8. PSW
                                    9. Subject
                                    10. Body

                                    As Jose's post #14 above points out, there are a number of other settings that could be implemented in SMTP code, but each author Diamond/Roca/Blat chose their own subsets (the 10 above plus a few others), not all of which I implemented in gbSendMail.

                                    You will want to review the original code/documentation to see the full extent of their code/implemented settings.

                                    Comment


                                    • #19
                                      gbSendMail v1.2 is now available for download.

                                      New Features:
                                      1. Added Paul Squires email class (with 2 unique settings, Authenticate and Authorization Type). The class includes suggested improvements by Ross, Doty and Brandel.

                                      I wanted Paul's work in gbSendMail primarily to make sure I'd covered the options given on the forums, but also because it was written as a class.

                                      It's worth nothing that Paul mentioned to me that he has since gone with Jose Roca's CDO approach, as it offered authenticated SSL which his ISP requires.

                                      Comment


                                      • #20
                                        Having been working with SMTP email code only for the last week or so, I can't say I have a "favorite" of the 4 options which are implemented in gbSendMail. I'm still trying to understand the differences between each solution, and the criteria for when I'd use each one.

                                        All four allow me to generate the PM-to-email utility that I've spoken of before, so the exercise of creating gbBlat/gbSendMail has worked out nicely for me.

                                        I don't have a GoDo list for gbSendMail, but if someone comes up with some changes they need, feel free to ask. If I cannot do it, then we'll ask the original authors for their help!

                                        Comment

                                        Working...
                                        X