Email Senden

  • Ne, ist VirusScan.
    Vorher hatte ich Version 7.3 und jetzt habe ich vor einiger Zeit auf Version 8.5 upgedated. Seitdem funktionierte es nicht mehr.

    Aber wenn man in den Einstellungen im Zugriffsschutz bei den Programmen, die Emails versenden dürfen Aut2exe.exe einträgt, dann funktioniert es wieder.

    --> Muss man auch erst mal drauf kommen :)

    Gruß

  • Hi,

    vermutlich nerv ich schön langsam, aber ich habe noch eine Frage:

    Ich habe jetzt diese neue Email-senden-Version, mit der man auch Attachments senden kann in mein Skript aufgenommen. Leider kann ich nur eine Datei senden.

    Ich habe schon versucht das Skript so zu verändern, dass man mehrere Dateien (Es müssten insgesamt 4 gesendet werden) senden kann. Aber es wird trotdem nur eine Datei gesendet...

    Soweit habe ich versucht es zu verändern. Leider verstehe ich die gesamte Funktion nicht, und so kann ich sie natürlich auch nicht verändern...

    [autoit]


    #Include<file.au3>
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

    [/autoit][autoit][/autoit][autoit]

    $s_SmtpServer = "mail.xxx.de"
    $s_FromName = @UserName
    $s_FromAddress = @UserName & "@xxx.de"
    $s_ToAddress = "srb@xxx.de"
    $s_Subject = "automatische Buchungsgenerierung fuer " & @UserName
    $as_Body = "text" & @CRLF
    $s_AttachFiles = "C:\Dokumente und Einstellungen\srb\Eigene Dateien\Buchungsvorlagen\2007-10-02 Bahn.htm"
    $s_AttachFiles2 = "C:\Dokumente und Einstellungen\srb\Eigene Dateien\Buchungsvorlagen\2007-10-02 Flug.htm" ;& "C:\Dokumente und Einstellungen\srb\Eigene Dateien\Buchungsvorlagen\2007-10-02 Flug.htm"
    $s_CcAddress = ""
    $s_BccAddress = ""
    $s_Username = ""
    $s_Password = ""
    $IPPort = 25
    $ssl = 1
    ;~ $ssl=1
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_AttachFiles2 = "", $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc)
    EndIf
    ;

    [/autoit][autoit][/autoit][autoit]

    Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "",$s_AttachFiles2 = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "",$IPPort=25, $ssl=0)
    $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body,"<") and StringInStr($as_Body,">") Then
    $objEmail.HTMLBody = $as_Body
    Else
    $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
    Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
    For $x = 1 To $S_Files2Attach[0]
    $S_Files2Attach[$x] = _PathFull ($S_Files2Attach[$x])
    If FileExists($S_Files2Attach[$x]) Then
    $objEmail.AddAttachment ($S_Files2Attach[$x])
    Else
    $i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
    SetError(1)
    return 0
    EndIf
    Next
    EndIf

    If $s_AttachFiles2 <> "" Then
    Local $S_Files2Attach = StringSplit($s_AttachFiles2, ";")
    For $x = 1 To $S_Files2Attach[0]
    $S_Files2Attach[$x] = _PathFull ($S_Files2Attach[$x])
    If FileExists($S_Files2Attach[$x]) Then
    $objEmail.AddAttachment ($S_Files2Attach[$x])
    Else
    $i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
    SetError(1)
    return 0
    EndIf
    Next
    EndIf

    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $Ssl Then
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Sent the Message
    $objEmail.Send
    if @error then
    SetError(2)
    return $oMyRet[1]
    EndIf
    EndFunc ;==>_INetSmtpMailCom
    ;
    ;
    ; Com Error Handler
    Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description,3)
    ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
    EndFunc ;==>MyErrFunc

    [/autoit]

    Kann mir da jemand helfen?

    Gruß

    • Offizieller Beitrag

    Hallo

    Sorry hab hier grad weder SciTe noch Autoit, aber wenn ich das richtig verstanden hab kannst du Mehrere Dateien senden in dem du sie bei $s_AttachFiles mit einem Simikolon ( ; ) trennst..
    Also z.B. so:

    [autoit]

    $s_AttachFiles = "C:\Dokumente und Einstellungen\srb\Eigene Dateien\Buchungsvorlagen\2007-10-02 Bahn.htm;C:\Dokumente und Einstellungen\srb\Eigene Dateien\Buchungsvorlagen\123.html;C:\TestDatei.exe"

    [/autoit]

    Mfg Spider

  • Hi,

    Oh mein Gott, Du bist ein Genie..

    Da hab ichs so lange versucht.. Und dann ist es so einfach.

    Ich hatte es schon so probiert, nur mit einem leer nach dem Semikolon, und auch mit einer &-Verknüpfung (also "file1" & "file2"), aber hat net funktioniert.

    Und jetzt sowas!

    Vielen lieben Dank!

  • Hi zusammen,

    habe zu dem Script, auf den peethebee verwiesen hat 2 Fragen.
    1. Kann ich ein Body mit mehreren Zeilen erstellen und wenn ja, wie?
    2. Was bedeuten diese Zeilen?
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    Wieso wird dort auf Microsoft Seiten verwiesen? Funktioniert der Script auch auf PC's die kein Inet Zugang haben?

    Danke für die Hilfe und Gruß
    Herra

  • hi herra,

    zu 1.

    ja das geht!

    entweder baust du dir den text vorher als variable zumsammen oder direkt bei der variable $as_Body !
    beispiel:
    $bodyinhalt = "test1" & @CRLF & "text2" (kannst den $bodyinhalt ja z.b auch aus ner textdatei auslesen und in die variable schreiben)
    $as_Body = $bodyinhalt
    oder
    $as_Body = "test1" & @CRLF & "text2"

    gruß gmmg

  • aber ich kann es trozdem nicht :<
    kann mir jemand helfen??

    [autoit]

    #Include<file.au3>
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

    [/autoit][autoit][/autoit][autoit]

    $s_SmtpServer = "smtp.live.com"
    $s_FromName = @UserName
    $s_FromAddress = "myemail@hotmail.com"
    $s_ToAddress = "uremail@hotmail.de"
    $s_Subject = "automatische Buchungsgenerierung fuer " & @UserName
    $as_Body = "text" & @CRLF
    $s_AttachFiles = "C:\Users\me\Desktop"
    $s_AttachFiles2 = ""
    $s_CcAddress = ""
    $s_BccAddress = ""
    $s_Username = ""
    $s_Password = ""
    $IPPort = 25
    $ssl = 0
    ;~ $ssl=1
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_AttachFiles2 = "", $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc)
    EndIf
    ;

    [/autoit][autoit][/autoit][autoit]

    Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "",$s_AttachFiles2 = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "",$IPPort=25, $ssl=0)
    $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body,"<") and StringInStr($as_Body,">") Then
    $objEmail.HTMLBody = $as_Body
    Else
    $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
    Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
    For $x = 1 To $S_Files2Attach[0]
    $S_Files2Attach[$x] = _PathFull ($S_Files2Attach[$x])
    If FileExists($S_Files2Attach[$x]) Then
    $objEmail.AddAttachment ($S_Files2Attach[$x])
    Else
    $i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
    SetError(1)
    return 0
    EndIf
    Next
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If $s_AttachFiles2 <> "" Then
    Local $S_Files2Attach = StringSplit($s_AttachFiles2, ";")
    For $x = 1 To $S_Files2Attach[0]
    $S_Files2Attach[$x] = _PathFull ($S_Files2Attach[$x])
    If FileExists($S_Files2Attach[$x]) Then
    $objEmail.AddAttachment ($S_Files2Attach[$x])
    Else
    $i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
    SetError(1)
    return 0
    EndIf
    Next
    EndIf

    [/autoit][autoit][/autoit][autoit]

    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $Ssl Then
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Sent the Message
    $objEmail.Send
    if @error then
    SetError(2)
    return $oMyRet[1]
    EndIf
    EndFunc ;==>_INetSmtpMailCom
    ;
    ;
    ; Com Error Handler
    Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description,3)
    ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
    EndFunc ;==>MyErrFunc

    [/autoit]

    dann kommt folgende fehlermeldung:
    Error code:1 Rc:0


    hmmmm...
    ich habe Hotmail.com adresse und will auch auf eine hotmail.de senden....Danke!...

  • Das Problem liegt höchstwahrscheinlich an hotmail. Hotmail bruacht nämlich eine SSL-Verbindung um per SMTP senden zu können. Erstell dir Testweise mal einen gmx.de account (achte auch darauf, dass die Adressdaten bestätigt sind, sonst darfst du auch damit nicht per SMTP senden) und probier es damit.