• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

Outlook e-mails automatisch versturen zonder toestemming te geven

Status
Niet open voor verdere reacties.

sanders1969

Gebruiker
Lid geworden
29 dec 2018
Berichten
243
Als ik onderstaande code run om het Outlook object in te zetten om e-mails te versturen via Excel.
Echter wordt er om een bevestiging gevraagd en ik wil dit direct versturen ipv via een popup toestemming geven.
Kan je deze popup in de code uitschakelen?
Punt is dat er bij mij thuis deze bevestiging niet plaatsvind echter bij de opdrachtgever wel.

Code:
    Set OL = CreateObject("outlook.application")

    Set bericht = OL.CreateItem(olMailItem)
    
    With bericht

        .Subject = "ONDERWERP”

        .HTMLBody = “HTML BERICHT”

        .Recipients.Add e-mail@hotmail.com

        .Send

    End With
 

Bijlagen

  • printscreen_email1.png
    printscreen_email1.png
    27,9 KB · Weergaven: 53
  • printscreen_email2.png
    printscreen_email2.png
    16,3 KB · Weergaven: 58
Je kunt mail wel degelijk versturen zonder CDO, dus met VBA code. Ik zal de code vanavond wel even posten.
 
Thanks want de organisatie waar ik werk, werk ik los van de ict afdeling en ik verwacht niet dat de ict afdeling de smtpgegevens en wachtwoorden van e-mailaccounts gaan doorgeven.
Ik kan mijn eigen smtp gegevens invullen maar dat lijk me niet de bedoeling.
 
Onderstaande is CDO en zoals je kan zien heb je accountgegevens nodig van het e-mailadres:

Code:
Sub Office365_Email_Test()
    Dim objMessage, objConfig, fields
    Set objMessage = New CDO.Message
    Set objConfig = New CDO.Configuration
    Set fields = objConfig.fields
    With fields
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username@office365.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Office365Password"
        '.Item("http://schemas.microsoft.com/cdo/configuration/sendtls") = True
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        .Update
    End With
    Set objMessage.Configuration = objConfig
    
    With objMessage
        .Subject = "Test Message"
        .From = "username@office365.com"
        .To = "someone@somedomain.com"
        .HTMLBody = "Test Message"
    End With
    objMessage.Send
End Sub
 
Dat klopt en dat is het nadeel inderdaad.
Ik ben benieuwd naar de oplossing van Octafish :)
 
In access werk ik met een smtp.ocx waar je ook onderwater kan e-mailen zelfs zonder Outlook geactiveerd te hebben echter mag ik geen installaties doen (registry), is geheel beschermd door ict.
 
Is in ieder geval een goede IT-afdeling. :d Ga er niet omheen lopen knutselen maar zorg in overleg met IT voor een passende oplossing. (ze blokken het niet voor niets)
 
Dit is de code die ik gebruik.
Code:
Public Function FnSendMailSafe(strTo As String, strCC As String, strBCC As String, strSubject As String, _
    strMessageBody As String, Optional strAttachments As String) As Boolean

' Simply sends an e-mail using Outlook/Simple MAPI.
' Calling this function by Automation will prevent the warnings
' A program is trying to send a mesage on your behalf...'
' Also features optional HTML message body and attachments by file path.
'
' The To/CC/BCC/Attachments function parameters can contain multiple items by seperating
' them by a semicolon. (e.g. for the strTo parameter, 'test@test.com; test2@test.com' is
' acceptable for sending to multiple recipients.
'
' (c) 2005 Wayne Phillips - Written 07/05/2005
' Last updated 26/03/2008 - Bugfix for empty varRecipient strings
' http://www.everythingaccess.com

On Error GoTo ErrorHandler:

Dim MAPISession As Outlook.NameSpace
Dim MAPIFolder As Outlook.MAPIFolder
Dim MAPIMailItem As Outlook.MailItem
Dim oRecipient As Outlook.Recipient
Dim TempArray() As String
Dim varArrayItem As Variant
Dim strEmailAddress As String
Dim strAttachmentPath As String
Dim blnSuccessful As Boolean

    'Get the MAPI NameSpace object
    Set MAPISession = Application.Session

    If Not MAPISession Is Nothing Then
        'Logon to the MAPI session
        MAPISession.Logon , , True, False
        'Create a pointer to the Outbox folder
        Set MAPIFolder = MAPISession.GetDefaultFolder(olFolderOutbox)
        If Not MAPIFolder Is Nothing Then
            'Create a new mail item in the "Outbox" folder
            Set MAPIMailItem = MAPIFolder.Items.Add(olMailItem)
            If Not MAPIMailItem Is Nothing Then
                With MAPIMailItem
                    'Create the recipients TO
                    TempArray = Split(strTo, ";")
                    For Each varArrayItem In TempArray
                        strEmailAddress = Trim(varArrayItem)
                        If Len(strEmailAddress) > 0 Then
                            Set oRecipient = .Recipients.Add(strEmailAddress)
                            oRecipient.Type = olTo
                            Set oRecipient = Nothing
                        End If
                    Next varArrayItem
                    'Create the recipients CC
                    TempArray = Split(strCC, ";")
                    For Each varArrayItem In TempArray
                        strEmailAddress = Trim(varArrayItem)
                        If Len(strEmailAddress) > 0 Then
                            Set oRecipient = .Recipients.Add(strEmailAddress)
                            oRecipient.Type = olCC
                            Set oRecipient = Nothing
                        End If
                    Next varArrayItem
                    'Create the recipients BCC
                    TempArray = Split(strBCC, ";")
                    For Each varArrayItem In TempArray
                        strEmailAddress = Trim(varArrayItem)
                        If Len(strEmailAddress) > 0 Then
                            Set oRecipient = .Recipients.Add(strEmailAddress)
                            oRecipient.Type = olBCC
                            Set oRecipient = Nothing
                        End If
                    Next varArrayItem
                    'Set the message SUBJECT
                    .Subject = strSubject
                    'Set the message BODY (HTML or plain text)
                    If StrComp(Left(strMessageBody, 6), "<HTML>", vbTextCompare) = 0 Then
                        .HTMLBody = strMessageBody
                    Else
                        .Body = strMessageBody
                    End If
                    'Add any specified attachments
                    TempArray = Split(strAttachments, ";")
                    For Each varArrayItem In TempArray
                        strAttachmentPath = Trim(varArrayItem)
                            If Len(strAttachmentPath) > 0 Then
                            .Attachments.Add strAttachmentPath
                            End If
                    Next varArrayItem
                    .Send 'No return value since the message will remain in the outbox if it fails to send
                    Set MAPIMailItem = Nothing
                End With
            End If
            Set MAPIFolder = Nothing
        End If
        MAPISession.Logoff
    End If

    'If we got to here, then we shall assume everything went ok.
    blnSuccessful = True

ExitRoutine:
    Set MAPISession = Nothing
    FnSendMailSafe = blnSuccessful

    Exit Function

ErrorHandler:
    MsgBox "An error has occured in the user defined Outlook VBA function FnSendMailSafe()" & vbCrLf & vbCrLf & _
            "Error Number: " & CStr(Err.Number) & vbCrLf & _
            "Error Description: " & Err.Description, vbApplicationModal + vbCritical
    Resume ExitRoutine

End Function
Kijk maar eens of je er wat aan hebt.
 
Je hebt/had natuurlijk ook nog het programmaatje ClickYes dat je als workaround kan gebruiken. Mits dat mag natuurlijk :).
 
Nou zeg, die had ik inderdaad niet gezien. Ik dacht dat ik altijd een e-mail kreeg van helpmij wanneer er een reactie is geplaatst.
Sorry Octafish, ik ga er meteen mee aan de slag!
Ik kan het alleen runnen maar niet testen omdat ik vandaag niet bij de opdrachtgever ben.
Maar ik laat je gegarandeerd eea weten.
Nogmaals dank!
 
Dit is de code die ik gebruik.
Code:
Public Function FnSendMailSafe(strTo As String, strCC As String, strBCC As String, strSubject As String, _
    strMessageBody As String, Optional strAttachments As String) As Boolean

' Simply sends an e-mail using Outlook/Simple MAPI.
' Calling this function by Automation will prevent the warnings
' A program is trying to send a mesage on your behalf...'
' Also features optional HTML message body and attachments by file path.
'
' The To/CC/BCC/Attachments function parameters can contain multiple items by seperating
' them by a semicolon. (e.g. for the strTo parameter, 'test@test.com; test2@test.com' is
' acceptable for sending to multiple recipients.
'
' (c) 2005 Wayne Phillips - Written 07/05/2005
' Last updated 26/03/2008 - Bugfix for empty varRecipient strings
' http://www.everythingaccess.com

On Error GoTo ErrorHandler:

Dim MAPISession As Outlook.NameSpace
Dim MAPIFolder As Outlook.MAPIFolder
Dim MAPIMailItem As Outlook.MailItem
Dim oRecipient As Outlook.Recipient
Dim TempArray() As String
Dim varArrayItem As Variant
Dim strEmailAddress As String
Dim strAttachmentPath As String
Dim blnSuccessful As Boolean

    'Get the MAPI NameSpace object
    Set MAPISession = Application.Session

    If Not MAPISession Is Nothing Then
        'Logon to the MAPI session
        MAPISession.Logon , , True, False
        'Create a pointer to the Outbox folder
        Set MAPIFolder = MAPISession.GetDefaultFolder(olFolderOutbox)
        If Not MAPIFolder Is Nothing Then
            'Create a new mail item in the "Outbox" folder
            Set MAPIMailItem = MAPIFolder.Items.Add(olMailItem)
            If Not MAPIMailItem Is Nothing Then
                With MAPIMailItem
                    'Create the recipients TO
                    TempArray = Split(strTo, ";")
                    For Each varArrayItem In TempArray
                        strEmailAddress = Trim(varArrayItem)
                        If Len(strEmailAddress) > 0 Then
                            Set oRecipient = .Recipients.Add(strEmailAddress)
                            oRecipient.Type = olTo
                            Set oRecipient = Nothing
                        End If
                    Next varArrayItem
                    'Create the recipients CC
                    TempArray = Split(strCC, ";")
                    For Each varArrayItem In TempArray
                        strEmailAddress = Trim(varArrayItem)
                        If Len(strEmailAddress) > 0 Then
                            Set oRecipient = .Recipients.Add(strEmailAddress)
                            oRecipient.Type = olCC
                            Set oRecipient = Nothing
                        End If
                    Next varArrayItem
                    'Create the recipients BCC
                    TempArray = Split(strBCC, ";")
                    For Each varArrayItem In TempArray
                        strEmailAddress = Trim(varArrayItem)
                        If Len(strEmailAddress) > 0 Then
                            Set oRecipient = .Recipients.Add(strEmailAddress)
                            oRecipient.Type = olBCC
                            Set oRecipient = Nothing
                        End If
                    Next varArrayItem
                    'Set the message SUBJECT
                    .Subject = strSubject
                    'Set the message BODY (HTML or plain text)
                    If StrComp(Left(strMessageBody, 6), "<HTML>", vbTextCompare) = 0 Then
                        .HTMLBody = strMessageBody
                    Else
                        .Body = strMessageBody
                    End If
                    'Add any specified attachments
                    TempArray = Split(strAttachments, ";")
                    For Each varArrayItem In TempArray
                        strAttachmentPath = Trim(varArrayItem)
                            If Len(strAttachmentPath) > 0 Then
                            .Attachments.Add strAttachmentPath
                            End If
                    Next varArrayItem
                    .Send 'No return value since the message will remain in the outbox if it fails to send
                    Set MAPIMailItem = Nothing
                End With
            End If
            Set MAPIFolder = Nothing
        End If
        MAPISession.Logoff
    End If

    'If we got to here, then we shall assume everything went ok.
    blnSuccessful = True

ExitRoutine:
    Set MAPISession = Nothing
    FnSendMailSafe = blnSuccessful

    Exit Function

ErrorHandler:
    MsgBox "An error has occured in the user defined Outlook VBA function FnSendMailSafe()" & vbCrLf & vbCrLf & _
            "Error Number: " & CStr(Err.Number) & vbCrLf & _
            "Error Description: " & Err.Description, vbApplicationModal + vbCritical
    Resume ExitRoutine

End Function
Kijk maar eens of je er wat aan hebt.


Wellicht doe ik iets verkeerd maar het loopt vast op regel: "Set MAPISession = Application.Session"
Foutmelding kan je hieronder zien en ik roep dit aan in Excel Office 365.
Moet ik een referentie toevoegen?

Foutmelding:
An error has occured in the user defined Outlook VBA function FnSendMailSafe()

Error Number: 438
Error Description: Deze eigenschap of methode wordt niet ondersteund door dit object
 
Wellicht doe ik iets verkeerd maar het loopt vast op regel: "Set MAPISession = Application.Session"
Foutmelding kan je hieronder zien en ik roep dit aan in Excel Office 365.
Moet ik een referentie toevoegen?

Foutmelding:
An error has occured in the user defined Outlook VBA function FnSendMailSafe()

Error Number: 438
Error Description: Deze eigenschap of methode wordt niet ondersteund door dit object

Onderstaande is de lijst referenties
error_email_excel.png
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan