Sie wollen mittels GuiXT und der callvbs Funktion ein E-Mail inkl. mehreren Attachments versenden.

Der Aufruf des Scriptes erfolgt wie folgt:

callvbs SendMail_with_attachment „test@koehn.ch“ „test2@koehn.ch“ „Titel Mail“ „bodytextid“ „Attachments“

wobei die beiden ersten Parameter den Empfänger und Sender beinhalten.

Der dritte Parameter beeinhaltet den Titel der Mail

Der vierte Parameter der Name der GuiXT Langtextvariable, wobei in dem Langtext HTML Coding erwartet wird.

Der letzte Parameter beeinhaltet der Name der GuiXT Langtextvariablen, der pro Zeile das jeweilige Attachment beeinhlatet.

Also z.b:

C:\Temp\Attachment1.txt
D:\Beispiele\Attachment2.pdf

VBS Script:

Sub SendMail_with_attachment(email_to, email_from, subject, bodytextid, attachment)

Dim vbCrLf
  Dim sAttachments, xAttachment, iAttachment, sAttachment

  ' Zeilenumbruch  
  vbCrLf = Chr(13) & Chr(10)

  ' Attachments holen
  sAttachments = GuiXT.GetText(attachment)
  ' Attachments splitten
  xAttachment = Split(sAttachments, vbNewLine, -1, 1)

  Dim objMessage

  Set objMessage = GuiXT.CreateObject("CDO.Message") 

  ' Set email parameters
  objMessage.Subject = subject
  objMessage.From = email_from 
  objMessage.To = email_to
  objMessage.HTMLBody = GuiXT.GetText(bodytextid) 

'objMessage.AddAttachment  attachment
  ' Attachment Array durchlaufen
  For iAttachment = LBound(xAttachment, 1) To UBound(xAttachment, 1)
    sAttachment = Trim(xAttachment(iAttachment))
    If Len(sAttachment) > 0 Then
      objMessage.AddAttachment sAttachment
    End If
  Next 
  ' SMTP configuation
  objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
  ' SMTP Server: 
  objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.ihreigenerserver.com"
  'SMTP Server: Server port (typically 25)
  objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  ' SMTP Server:  User
  objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "IhrUser"     
  ' SMTP Server: Password
  objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password"      
  'SMTP Server: Authentification
  objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 

  'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
  objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

  ' update configuration
  objMessage.Configuration.Fields.Update

  ' Send message
  objMessage.Send 
  Set objMessage = Nothing

End Sub

Empfehlen