martenk
Goto Top

Mailversand aus Access über Outlook

Hallo,

ich habe eine Frage bzgl. des Mailversands aus Access heraus - habe ein Mailingscript, welches für den Versand ein falsches Konto verwendet - könnt ihr mir sagen, wo ich das einstellen kann

das ist der Teil, wo die Mail erstellt und versendet wird

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim Betreff As String: Betreff = "Abrechnung"  
Dim Nachricht As String, an As String, ATT1
Dim db As Database, rs As Recordset
Dim html

.
.
.
'Mailobjekt erstellen  
  Set objOutlook = CreateObject("Outlook.Application")  
  Set objOutlookMsg = objOutlook.CreateItem(0)
 
  'Tabelle "Verteiler" auslesen.  
  Set db = CurrentDb
  Set rs = db.OpenRecordset("Verteiler", dbOpenDynaset)  
  DoCmd.Echo True
  If rs.EOF Then MsgBox "Keine Empfänger im Verteiler", vbExclamation: GoTo Ex  
 
  With objOutlookMsg
    'Durch alle Empfänger  
    Do While Not rs.EOF
      an = Nz(rs!Name, "")  
      If an <> "" Then .Recipients.Add an  
      rs.MoveNext
    Loop
   'Inhalt des Mails festlegen  
     .Importance = 0 ' niedrige priorität  
    .Subject = Betreff
    .HTMLBody = html   'HTML-Format  
    .Attachments.Add ATT1 'Berichte anhängen  
    '.Attachments.Add ATT2  
    For Each objOutlookRecip In .Recipients
      objOutlookRecip.Resolve 'Namen überprüfen  
    Next
    '.Display 'Nachricht wird angezeigt  
    .Send   'Nachricht wird sofort gesendet  
  End With

Content-Key: 667095

Url: https://administrator.de/contentid/667095

Printed on: April 20, 2024 at 01:04 o'clock

Mitglied: 148121
148121 May 26, 2021 updated at 14:32:45 (UTC)
Goto Top
Damit
' ...  
dim acc as Object, selAcc as Object
for each acc in objOutlook.Session.Accounts
    if acc.SmtpAddress = "user@domain.tld" then set selAcc = acc  
Next
if not selAcc is Nothing then
   set objOutlookMsg.SendUsingAccount = selAcc
End if
' ...  
Bitte lesen bevor gefragt wird:
https://docs.microsoft.com/de-de/office/vba/api/outlook.mailitem.sendusi ...

Gruß w.
Member: martenk
martenk May 26, 2021 at 13:54:41 (UTC)
Goto Top
da bekomme ich die Meldung Objektvariable nicht festgelegt - sie ist doch mit DIM festgelegt
Mitglied: 148121
148121 May 26, 2021 updated at 13:57:06 (UTC)
Goto Top
Kleiner Tippfehler auf meiner Seite hatte das "set" vergessen, ist oben korrigiert...
Member: martenk
martenk May 26, 2021 at 14:17:39 (UTC)
Goto Top
Fehler bleibt leider
Mitglied: 148121
148121 May 26, 2021 updated at 14:37:25 (UTC)
Goto Top
Kopiers nochmal (vermutlich veralteter Browser Cache oder hast's and der falschen Stelle eingefügt) lüppt hier problemlos ...
Breakpoints und F8 sind deine Freunde, und nicht immer so viel copy und pasten, das lässt nämlich die grauen Zellen verkümmern! face-wink.

Ich bin raus. Case closed.
Member: martenk
martenk May 27, 2021 updated at 07:58:41 (UTC)
Goto Top
so gemacht, wie du geschrieben hattest - Fehler bleibt

bleibt hängen bei dieser Zeile

for each acc in objOutlook.Session.Accounts

kann es an den Verweisen liegen

ich habe mal dieses Script probiert

Sub SendUsingAccount()
 
 Dim oAccount As Outlook.Account
 
 For Each oAccount In Application.Session.Accounts
 
 If oAccount.AccountType = olPop3 Then
 
 Dim oMail As Outlook.MailItem
 
 Set oMail = Application.CreateItem(olMailItem)
 
     oMail.Subject = "Sent using POP3 Account"  
 
     oMail.Recipients.Add ("someone@example.com")  
 
     oMail.Recipients.ResolveAll
 
 Set oMail.SendUsingAccount = oAccount
 
     oMail.Send
 
 End If
 
 Next
 
End Sub

das bleibt hier hängen - in einer neuen Datenbank
For Each oAccount In Application.Session.Accounts