Announcement

Collapse
No announcement yet.

Email to draft folder same machine

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

  • Email to draft folder same machine

    A customer wants to created pdf statements (done). Now they want those pdf statements attached to a generic email and placed in the draft folder in her Microsoft Outlook. She then wants to call them up one by one, review and send them on. Later she would like all the items in the draft folder to be sent automatically by using a program.

    I've been looking for hours in the forum and a lot of the code doesn't work and nothing specifically about sending to the draft folder or any kind of mass sending from the draft folder to the outbox.

    Seems this customer will not allow the use of a username and password to authenticate otherwise I'd used SMTP (a method I've already got working thanks to sample code here).

    I've seen this done in VB but wonder if PB 9 might be the way to do this using MAPI save? instead of MAPI send.

    Help!
    Thanks,

    Bob Mechler

  • #2
    The following VB6 classmodule code does what I want. How would this look in pb7.04 and COM?

    Code:
    Private m_olApplication As Outlook.Application
    Private m_olNameSpace As Outlook.NameSpace
    Private m_olMailItem As Outlook.MailItem
    Public Sub MailReport(ByVal rptname As String, _
                          ByVal draft As Boolean, _
                          ByVal workpath As String)
                                   
        'create Outlook application
        Set m_olApplication = New Outlook.Application
          
        'get nameSpace and logon
    
        Set m_olNameSpace = m_olApplication.GetNamespace("mapi")
        m_olNameSpace.Logon "Outlook", "", False, True
           
        Set m_olMailItem = m_olApplication.CreateItem(olMailItem)
        
        m_olMailItem.To = "[email protected]"
        m_olMailItem.Subject = "Sample email"
        m_olMailItem.Body = "Now is the time for all good menu "
        m_olMailItem.Attachments.Add workpath & "\" & rptname
        If draft Then
           m_olMailItem.Save
        Else
           m_olMailItem.Send
        End If
                
       Set m_olMailItem = Nothing
       Set m_olNameSpace = Nothing
       Set m_olApplication = Nothing
       
       'Kill workpath & "\" & rptname
    End Sub
    I used this code on a button on a plain form to crank it up
    Code:
    Private Sub Command1_Click()
      Dim rptname As String, parts() As String
      Dim draft As Boolean, workpath As String
    
      parts = Split(Command$, " ") 'starting at 0
      rptname = "comc.pdf"          'parts(0) this will be used after testing
      draft = 1                           'parts(1)
      workpath = "c:\pdfs\"          'parts(2)
    
      Dim rpt As ClassEmailPdf
      Set rpt = New ClassEmailPdf
      Call rpt.MailReport(rptname, draft, workpath)
    
    End Sub
    Is it easier to do in PB 9?

    Bob Mechler

    Comment


    • #3
      Looks like I'm posting to myself here but anyway, the following sends emails to the current users draft folder but the attachment statement doesn't work. What am I doing wrong?

      Code:
      #COMPILE EXE "pbemail.exe"
      #INCLUDE"WIN32API.INC"
      #INCLUDE"oOUTLOOK.INC"
      FUNCTION PBMAIN
        DIM o_mlApplication AS OutlookApplication
        DIM o_mlNameSpace AS OutLookNameSpace
        DIM o_mlMailitem AS OutLookMailItem
        DIM vSpace AS VARIANT
        DIM vMapi AS VARIANT
        DIM vMail AS VARIANT
        DIM vItemType AS VARIANT
        DIM vSubject AS VARIANT
        DIM vBody AS VARIANT
        DIM vTo AS VARIANT
        DIM vVnt AS VARIANT
        'DIM o_ml_MailItem AS DISPATCH
        
        vMapi = "mapi"
        
        SET o_mlApplication = NEW OutLookApplication IN $PROGID_OutLookApplication9
        OBJECT CALL o_mlApplication.GetNameSpace(vMapi) TO vSpace
        
        SET o_mlNameSpace = vSpace
        OBJECT CALL o_mlNameSpace.Logon
      
        OBJECT CALL o_mlApplication.CreateItem(vItemType) TO vMail
        SET o_ml_MailItem = vMail
      
        vSubject = "Pb Email using Outlook"
        OBJECT LET o_ml_MailItem.Subject = vSubject
      
        vBody = "This is a test"+$CRLF+"This is the second line"+$CRLF
        OBJECT LET o_ml_MailItem.Body = vBody
      
        vTo = "[email protected]"
        OBJECT LET o_ml_MailItem.To = vTo
        
        vVnt = "c:\pdfs\COMC.PDF"
        OBJECT CALL o_ml_MailItem.Attachements.Add(vVnt)
        
        OBJECT CALL o_ml_MailItem.Save
        
         SET o_ml_MailItem = NOTHING
         SET o_mlNameSpace = NOTHING
         SET o_mlApplication = NOTHING
        'OBJECT CALL
        
        OBJECT CALL o_mlNameSpace.Logoff
      
      END FUNCTION
      
      Bob Mechler
      Last edited by BOB MECHLER; 18 Sep 2008, 10:33 PM.

      Comment


      • #4
        Found the error. The following works if you have Outlook.

        Code:
        #COMPILE EXE "pbemail.exe"
        #INCLUDE"WIN32API.INC"
        #INCLUDE"oOUTLOOK.INC"
        FUNCTION PBMAIN
          DIM o_mlApplication AS OutlookApplication
          DIM o_mlNameSpace AS OutLookNameSpace
          DIM o_mlMailitem AS OutLookMailItem
          DIM vSpace AS VARIANT
          DIM vMapi AS VARIANT
          DIM vMail AS VARIANT
          DIM vItemType AS VARIANT
          DIM vSubject AS VARIANT
          DIM vBody AS VARIANT
          DIM vTo AS VARIANT
          DIM vVnt AS VARIANT
          'Dim o_ml_MailItem As Dispatch
          
          vMapi = "mapi"
          
          SET o_mlApplication = NEW OutLookApplication IN $PROGID_OutLookApplication9
          OBJECT CALL o_mlApplication.GetNameSpace(vMapi) TO vSpace
          
          SET o_mlNameSpace = vSpace
          OBJECT CALL o_mlNameSpace.Logon
        
          OBJECT CALL o_mlApplication.CreateItem(vItemType) TO vMail
          SET o_mlMailItem = vMail
        
          vSubject = "Pb Email using Outlook"
          OBJECT LET o_mlMailItem.Subject = vSubject
        
          vBody = "This is a test"+$CRLF+"This is the second line"+$CRLF
          OBJECT LET o_mlMailItem.Body = vBody
        
          vTo = "[email protected]"
          OBJECT LET o_mlMailItem.To = vTo
          
          vVnt = "c:\pdfs\COMC.PDF"
          OBJECT CALL o_mlMailItem.Attachments.Add(vVnt)
          
          OBJECT CALL o_mlMailItem.Save
          
           SET o_mlMailItem = NOTHING
           SET o_mlNameSpace = NOTHING
           SET o_mlApplication = NOTHING
          'OBJECT CALL
          
          OBJECT CALL o_mlNameSpace.Logoff
        
        END FUNCTION
        Last edited by BOB MECHLER; 18 Sep 2008, 10:34 PM.

        Comment


        • #5
          Nagging Message using COM send

          With my NT Authentication I don't get any nagging messages. When another user runs the same email program, they get a message saying that someone is trying to send email.

          What ways can be used to get around this. Simple MAPI? We use exchange server and I don't thing it's installed at the moment.

          Bob Mechler

          Comment


          • #6
            I know with the Outlook Express' MAPI interface, the 'someone is trying to send mail as me' warning is controlled by a user security options setting.

            I have no clue if Outlook [no 'Express'] has a similar user option setting but I don't think I'd be shocked if it did and was used by the COM interface as well as the MAPI interface.

            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              I've seen some Outlook add-ins advertised that give an object to disable the message for less that Domain Admins.

              MSDN says that Outlook security patch took away the ability to program MAPI to instantiate a new instance of Outlook and send emails using COM unless the Windows Authentication was high enough not to trigger the warning. As a work-around they suggeste using Simple MAPi instead which is why I'm seeking info about it.

              I've downloaded some information about CDO also and see where that leads.

              Can't use SMTP because I need the email pdf's to optionally go to the draft folder first and when sent to end up in the sent folder for archiving.

              Bob Mechler

              Comment


              • #8
                OK, just to get this straight: Due to security concerns, your customer won't allow you to send directly from your application. Fair enough ...

                But than he rather would like your appliaction to have complete access to his Outlook, which not only would let you send anything that you could have sent via SMTP, but now you also gain access to all stored messages, contacts and what not?

                You might try to explain this paradoxon to your customer and see what he has to say about this. Remind him that as soon as one of his employees logs into Outlook and hands control over to you by using your add-on, you/your application could potentially do much more harm.

                Comment


                • #9
                  We call'em network nazis when the IT guy at the customer site convinces the owner or manager that legitimate access for a specific purpose that can be controlled is still a no-no.

                  I tracked down the nag message to occuring when a user is just a Domain user. Domain Admins can use this code without the nag message.

                  Three solutions I've come up with to use MAPI and no ADD-INS.

                  1. A normal domain user can run the program with the destination as Save which will put all the emails in the draft folder without a nag message. From there the logged in Domain user can select all the emails in the draft folder or a good chunk of them, right click and then open items. From there all the emails chosen will display. Then it's a matter of doing Alt-S for however many there are.

                  2. A normal domain user can have a Domain Admin Remote Desktop Login that is set to run exactly the program in question and send the emails then logout when it's done. There are no nag messages if a Domain Admin is running the program

                  3. A Domain Admin logs in and runs the program in question.

                  The customers want the email statement pdfs to be held and later archived by Outlook.

                  Bob Mechler

                  Comment

                  Working...
                  X