mail verzenden vanuit Drafts

Status
Niet open voor verdere reacties.

KrisVercammen

Gebruiker
Lid geworden
24 jun 2019
Berichten
6
Wanneer ik onderstaande uitvoer in Outlook, krijg ik steeds foutmelding, terwijl ik niets wijzigde en het oorspronkelijk wel alle mails uit "Drafts" verstuurde.

'Declare Sleep API
Private Declare Sub Sleep Lib "kernel32" (ByVal nMilliseconds As Long)

Sub SendAllDrafts()
' Send the messages in the Drafts folder (ignore any subfolders)
If MsgBox("Are you sure you want to send ALL the items in * Drafts folder?", _
vbQuestion + vbYesNo) <> vbYes Then Exit Sub

Dim fldDraft As MAPIFolder
Dim msg As Outlook.MailItem
Dim intCount As Integer

Set fldDraft = Outlook.Application.Folders("Drafts")

intCount = 0
Do While fldDraft.Items.Count > 0
Set msg = fldDraft.Items(1)
msg.Send
Sleep 500
intCount = intCount + 1
Loop
If Not (msg Is Nothing) Then Set msg = Nothing
Set fldDraft = Nothing
MsgBox intCount & " messages sent", vbInformation + vbOKOnly
End Sub
 
Misschien handig om ook even de betreffende foutmelding erbij te vermelden.
 
Foutboodschap: Run-time error '-2147024809(80070057)': Could not complete the operation. One or more parameter values are not valid.

Hierbij correcte gebruikte macro:
'Declare Sleep API
Private Declare Sub Sleep Lib "kernel32" (ByVal nMilliseconds As Long)

Sub SendAllDrafts()
' Send the messages in the Drafts folder (ignore any subfolders)
If MsgBox("Are you sure you want to send ALL the items in * Drafts folder?", _
vbQuestion + vbYesNo) <> vbYes Then Exit Sub

Dim fldDraft As MAPIFolder
Dim msg As Outlook.MailItem
Dim intCount As Integer

Set fldDraft = Outlook.GetNamespace("Drafts").Folder

intCount = 0
Do While fldDraft.Items.Count > 0
Set msg = fldDraft.Items(1)
msg.Send
Sleep 500
intCount = intCount + 1
Loop
If Not (msg Is Nothing) Then Set msg = Nothing
Set fldDraft = Nothing
MsgBox intCount & " messages sent", vbInformation + vbOKOnly
End Sub
 
En op welke regel krijg je die melding dan?
Heb je wel een 32-bit installatie van Office?
In een 64-bit Office zal het fout gaan op het op deze manier gebruiken van "kernel32".

Overigens doet deze het prima:
Code:
Sub SendAllDraftEmails()

  Dim objDrafts As Outlook.Items
  Dim objDraft As Object
  Dim strPrompt As String
  Dim nResponse As Integer
  Dim i As Long
  Dim merror As Integer, Gcount As Integer

  On Error GoTo err_handle

  Set objDrafts = Outlook.Application.Session.GetDefaultFolder(olFolderDrafts).Items
  Gcount = objDrafts.Count

  If objDrafts.Count > 0 Then
      strPrompt = "Are you sure you want to send out all the drafts?"
      nResponse = MsgBox(strPrompt, vbQuestion + vbYesNo, "Confirm Sending")

      If nResponse = vbYes Then
            For i = objDrafts.Count To 1 Step -1
                  objDrafts.item(i).Send

                  ' **** USE ONLY ON LARGE BATCHES OF (say) 500+ emails if you need to slow the program speed down ****
                  ' **** this next line will PAUSE the program for 2 seconds before sending the NEXT Draft email **

                   ' **** TO USE THE PROGRAM LINE REMOVE THE SINGLE QUOTE ' IN FRONT OF 'SLEEP 2000 ****
                  ' Sleep 2000
             Next
      End If

      If merror > 0 And merror = Gcount Then
             MsgBox "No Draft Emails Sent!", vbCritical, "Email Sending Errors!"
      ElseIf merror > 0 And merror < Gcount Then
             MsgBox "Some Draft Emails were sent - " & Trim(Str(merror)) & " emails were not sent", vbCritical, "Email Sending Errors!"
      Else
             MsgBox "All Draft Emails Sent!", vbInformation, "Email Sending"
      End If
  Else
      MsgBox "No Draft Emails Found!", vbExclamation, "No Draft Emails Found"
  End If

  Exit Sub

err_handle:

  If Err = "-2147467259" Then
      MsgBox "There must be at least one email address or contact group in the TO, CC or BCC fields" & vbCrLf & "Fix it and re-run your emails", vbExclamation, "Error in Email Address!"
      merror = 1 + merror
      Resume Next
  End If

End Sub
 
Laatst bewerkt:
op deze lijn geeft hij de foutmelding:

Set fldDraft = Outlook.GetNamespace("Drafts").Folder
 
Ik zou het stukje code gebruiken dat ik in #4 plaatste.
Die doet het in ieder geval goed.
 
ik krijg steeds volgende foutmelding in verzending nu:

Delivery has failed to these recipients or groups:
Middle.office.kredieten@belins.be (INVALID:Middle.office.kredieten@belins.be)
This message was rejected by the recipient email system. Please check the recipient's email address and try resending this message, or contact the recipient directly.





Diagnostic information for administrators:
Generating server: XW16LXAL0004.DVSYS.DV.BE
IMCEAINVALID-Middle+2Eoffice+2Ekredieten+40belins+2Ebe@belins.be
Remote Server returned '550 5.1.0 RESOLVER.ADR.InvalidInSmtp; encapsulated INVALID address inside an SMTP address (IMCEAINVALID-)'
Original message headers:
Received: from XW16LXAL0001.DVSYS.DV.BE (10.222.77.36) by
XW16LXAL0004.DVSYS.DV.BE (10.222.77.39) with Microsoft SMTP Server (TLS) id
15.0.1395.4; Mon, 24 Jun 2019 13:39:23 +0200
Received: from XW16LXAL0001.DVSYS.DV.BE ([10.222.77.36]) by
XW16LXAL0001.DVSYS.DV.BE ([10.222.77.36]) with mapi id 15.00.1395.000; Mon,
24 Jun 2019 13:39:23 +0200
Content-Type: application/ms-tnef; name="winmail.dat"
Content-Transfer-Encoding: binary
From: =?utf-8?B?TWlkZGxlIE9mZmljZSBrcmVkaWV0ZW4vY3LDqWRpdHM=?=
<middle.office.kredieten@belins.be>
To: "Middle.office.kredieten@belins.be"
<IMCEAINVALID-Middle+2Eoffice+2Ekredieten+40belins+2Ebe@belins.be>
CC: "Middle.office.kredieten@belins.be"
<IMCEAINVALID-Middle+2Eoffice+2Ekredieten+40belins+2Ebe@belins.be>,
"Middle.office.kredieten@belins.be"
<IMCEAINVALID-Middle+2Eoffice+2Ekredieten+40belins+2Ebe@belins.be>
Subject: Saldo Jokers per +6518541
Thread-Topic: Saldo Jokers per +6518541
Thread-Index: AdUqgWqiazhHD/u7T9qdlkNieL035A==
X-MS-Exchange-MessageSentRepresentingType: 1
Date: Mon, 24 Jun 2019 13:39:15 +0200
Message-ID: <d3fa095934b64b53b4da8dd8862283cd@XW16LXAL0001.DVSYS.DV.BE>
Accept-Language: fr-BE, en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator: <d3fa095934b64b53b4da8dd8862283cd@XW16LXAL0001.DVSYS.DV.BE>
MIME-Version: 1.0
X-MS-Exchange-Transport-FromEntityHeader: Hosted
X-Originating-IP: [10.122.196.165]
Return-Path: middle.office.kredieten@belins.be
 
Dit lijkt me duidelijk:
This message was rejected by the recipient email system

Het verzenden van de drafts gaat dus goed.
De betreffende mail wordt echter tegengehouden door het email systeem van de ontvanger.
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan