Automating Emails using CDO

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lazster
    New Member
    • Feb 2007
    • 5

    Automating Emails using CDO

    Hi,

    I am using Access in Office 2003 to try to automate messaging people in my organisation after a certain period has passed. I have managed to do this fine with what little knowledge I have, apart from the fact using Outlook creates a security confirmation message, which ruins the whole automation process. I cannot really bypass this.

    I read that using a CDO message would not create this security alert. However, I am not sure exactly how to connect to my server, or whether it would allow me to do this, I have tried to talk to IS, and they haven't got back to me.

    I've got various code examples from the internet and when I run them it asks about connection to the server, as below;
    Code:
    Public Function CDOMail_Click()
    
    Set cdoConfig = CreateObject("CDO.Configuration")
     
        With cdoConfig.Fields
            .Item(cdoSendUsingMethod) = cdoSendUsingPort
            .Item(cdoSMTPServer) = "<server name>" 'My server name from Outlook is D1EXC004
            .Update
        End With
     
        Set cdoMessage = CreateObject("CDO.Message")
     
        With cdoMessage
            Set .Configuration = cdoConfig
            .From = "peter.martin@rpa.gsi.gov.uk"
            .To = "peter.martin@rpa.gsi.gov.uk"
            .Subject = "Sample CDO Message"
            .TextBody = "This is a test for CDO.message"
            .Send
        End With
     
        Set cdoMessage = Nothing
        Set cdoConfig = Nothing
    
    End Function
    Any advice as to how to connect to the server for CDO messages would be appreciated
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Originally posted by Lazster
    I am using Access in Office 2003 to try to automate messaging people in my organisation after a certain period has passed. I have managed to do this fine with what little knowledge I have, apart from the fact using Outlook creates a security confirmation message, which ruins the whole automation process. I cannot really bypass this.
    This is an outlook setting and can be turned off in outlook. This would probably not be allowed by your company for security reasons though.

    Originally posted by Lazster
    I read that using a CDO message would not create this security alert. However, I am not sure exactly how to connect to my server, or whether it would allow me to do this, I have tried to talk to IS, and they haven't got back to me.

    I've got various code examples from the internet and when I run them it asks about connection to the server, as below;
    [CODE=vb]
    Public Function CDOMail_Click()

    Set cdoConfig = CreateObject("C DO.Configuratio n")

    With cdoConfig.Field s
    .Item(cdoSendUs ingMethod) = cdoSendUsingPor t
    .Item(cdoSMTPSe rver) = "<server name>" 'My server name from Outlook is D1EXC004
    .Update
    End With

    Set cdoMessage = CreateObject("C DO.Message")

    With cdoMessage
    Set .Configuration = cdoConfig
    .From = "peter.martin@r pa.gsi.gov.uk"
    .To = "peter.martin@r pa.gsi.gov.uk"
    .Subject = "Sample CDO Message"
    .TextBody = "This is a test for CDO.message"
    .Send
    End With

    Set cdoMessage = Nothing
    Set cdoConfig = Nothing

    End Function
    [/CODE]
    Any advice as to how to connect to the server for CDO messages would be appreciated
    I don't use CDO so I will leave this for someone else to answer.

    Comment

    • JConsulting
      Recognized Expert Contributor
      • Apr 2007
      • 603

      #3
      Originally posted by Lazster
      Hi,

      I am using Access in Office 2003 to try to automate messaging people in my organisation after a certain period has passed. I have managed to do this fine with what little knowledge I have, apart from the fact using Outlook creates a security confirmation message, which ruins the whole automation process. I cannot really bypass this.

      I read that using a CDO message would not create this security alert. However, I am not sure exactly how to connect to my server, or whether it would allow me to do this, I have tried to talk to IS, and they haven't got back to me.

      I've got various code examples from the internet and when I run them it asks about connection to the server, as below;

      Public Function CDOMail_Click()

      Set cdoConfig = CreateObject("C DO.Configuratio n")

      With cdoConfig.Field s
      .Item(cdoSendUs ingMethod) = cdoSendUsingPor t
      .Item(cdoSMTPSe rver) = "<server name>" 'My server name from Outlook is D1EXC004
      .Update
      End With

      Set cdoMessage = CreateObject("C DO.Message")

      With cdoMessage
      Set .Configuration = cdoConfig
      .From = "peter.martin@r pa.gsi.gov.uk"
      .To = "peter.martin@r pa.gsi.gov.uk"
      .Subject = "Sample CDO Message"
      .TextBody = "This is a test for CDO.message"
      .Send
      End With

      Set cdoMessage = Nothing
      Set cdoConfig = Nothing

      End Function

      Any advice as to how to connect to the server for CDO messages would be appreciated

      here is the code I use to send mail using CDO

      [code=vb]
      Public Function SendEmailCDO(By Val strTo As String, _
      ByVal strMessage As String, _
      ByVal strSubject As String, _
      Optional ByVal strAttach As String)
      Dim objEmail As Object
      On Error Resume Next
      Set objEmail = CreateObject("C DO.Message")
      '**** email address of sender
      objEmail.FROM = "fred@smith.com "
      objEmail.To = strTo
      objEmail.Subjec t = strSubject
      objEmail.TextBo dy = strMessage
      If strAttach <> "" Then objEmail.AddAtt achment strAttach
      objEmail.Config uration.Fields. Item( "http://schemas.microso ft.com/cdo/configuration/sendusing")=2
      '*** smtp.xxx.com - here u enter your smtp server name, whatever that is
      objEmail.Config uration.Fields. Item( "http://schemas.microso ft.com/cdo/configuration/smtpserver")="s mtp.xx.com"
      objEmail.Config uration.Fields. Item( "http://schemas.microso ft.com/cdo/configuration/smtpserverport" )=25
      objEmail.Config uration.Fields. Update
      objEmail.Send
      If err.Number <> 0 Then
      MsgBox "Error in sending. " & err.Description
      Else
      MsgBox "Sent" 'remove this if u dont want confirmation
      End If
      Set objEmail = Nothing

      End Function
      [/code]

      let me know if you need any followup.
      J

      Comment

      • JodiPhillips
        New Member
        • May 2007
        • 26

        #4
        J can CDO be used to open a .oft?

        Comment

        • JConsulting
          Recognized Expert Contributor
          • Apr 2007
          • 603

          #5
          Originally posted by JodiPhillips
          J can CDO be used to open a .oft?
          .oft?

          not sure what that is.

          Comment

          • JodiPhillips
            New Member
            • May 2007
            • 26

            #6
            Originally posted by JConsulting
            .oft?

            not sure what that is.
            .oft is an Outlook file template. Not sure if you can combine a CDO message and open a template file at the same time? I'm looking at doing this but not sure if I'm going about it the right way.

            Edit: typos and sentence restructure

            Comment

            • JodiPhillips
              New Member
              • May 2007
              • 26

              #7
              Originally posted by JodiPhillips
              .oft is an Outlook file template. Not sure if you can combine a CDO message and open a template file at the same time? I'm looking at doing this but not sure if I'm going about it the right way.

              Edit: typos and sentence restructure
              Gawd! I apologise sincerely for this "stupid" and "ignorant" question!! Have since done some other reading and now realise that this is wayyyyyy off the planet.

              Jodi

              Comment

              • gls0151
                New Member
                • Jan 2007
                • 1

                #8
                [QUOTE=mmccarthy]This is an outlook setting and can be turned off in outlook. This would probably not be allowed by your company for security reasons though.

                I am attempting this same process, and have the access rights to turn this setting off if I knew where to find it :). Can you tell me how to turn the prompt off in Outlook? Thanks!!!

                Comment

                • MMcCarthy
                  Recognized Expert MVP
                  • Aug 2006
                  • 14387

                  #9
                  Originally posted by gls0151
                  Originally posted by mmccarthy
                  This is an outlook setting and can be turned off in outlook. This would probably not be allowed by your company for security reasons though.
                  I am attempting this same process, and have the access rights to turn this setting off if I knew where to find it :). Can you tell me how to turn the prompt off in Outlook? Thanks!!!
                  In Outlook 2000 or earlier go to options and under the security tab click on Attachment Security. Be careful though as this disables all attachment security.

                  In Outlook 2003 or later you will need to use automation VBA code as follows

                  [CODE=vb]
                  OlSecurityManag er.ConnectTo OutlookApp
                  OlSecurityManag er.DisableOOMWa rnings = True
                  On Error Goto Finally

                  '... send your mails here ...

                  Finally: OlSecurityManag er.DisableOOMWa rnings = False
                  [/CODE]

                  Comment

                  Working...