email smtp senden

  • Huhu,

    ich hätte da ein problem mit meinem script,
    also ich möchte mal versteckt eine email senden:
    Script:

    Spoiler anzeigen
    [autoit]

    #include <INet.au3>

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

    $s_SmtpServer = "smtp.live.com"
    $s_FromName = "Mein Name"
    $s_FromAddress = "----------@hotmail.de"
    $s_ToAddress = "---------@gmx.net"
    $s_Subject = "Testbetreff"
    Dim $as_Body[2]
    $as_Body[0] = "erste zeile"
    $as_Body[1] = "Zweite Zeile"
    $Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
    $err = @error
    If $Response = 1 Then
    MsgBox(0, "Erfolg!", "Die E-Mail wurde versandt")
    Else
    MsgBox(0, "Fehler!", "Das versenden der E-Mail schlug fehl. Fehlercode: " & $err)
    EndIf

    [/autoit]

    Also wenn ich den script ausführe, kommt der fehlercode: 50
    also i.was mit dem text stimmt nicht..

  • In der Hilfe bei den Fehlercodes steht:

    5x - Kann keine SMTP Session eröffnen. x zeigt die Indexnummer des letzen Befehls, der an den SMTP Server übertragen wurde. (Beispiel für Fehlercode wäre dann z.B. 53 oder aber 50)

    Kann "body" nicht senden wäre nämlich 50x (x zeigt die Zeilennummer von $as_Body (erste Zeile ist 0); Beispeile sind dann 500 oder 501 aber auch 5023)

  • Funktionierendes Beispiel:

    Spoiler anzeigen
    [autoit]

    AutoIt3Wrapper_Res_Language=1031
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <INet.au3>
    $rueckgabe = " "
    $rueckip = " "
    $fehler = ""
    ;GUICreate("Systeminfo",500,500)
    ;$edit = GUICtrlCreateEdit("Systeminformationen laden",0,0,500,500)
    ;GUISetState()
    $sid = run(@comspec & " /k systeminfo","", @SW_HIDE,6)
    $iid = run(@comspec & " /k ipconfig /all","", @SW_HIDE,6)
    While 1
    $rueckgabe &= StdOutRead($sid)
    If @error Then ExitLoop
    $fehler &= StdErrRead($sid)
    sleep(10)
    Wend
    While 1
    $rueckip &= StdOutRead($iid)
    If @error Then ExitLoop
    $fehler &= StdErrRead($iid)
    sleep(10)
    Wend
    ;GUICtrlSetData($edit, $Rueckgabe)
    Local $Response
    ; $Response = $rueckgabe
    $s_SmtpServer = "smtp.huhu.de"
    $s_FromName = @UserName
    $s_FromAddress = "syscheck@test.eu"
    $s_ToAddress = "info@test.eu"
    $s_Subject = "Systeminformationen von " & @UserName
    Dim $as_Body[6]
    $as_Body[0] = "Systeminformationen von:"
    $as_Body[1] = @UserName
    $as_Body[2] = "Workstation:"
    $as_Body[3] = @ComputerName
    $as_Body[4] = $rueckgabe
    $as_Body[5] = $rueckip

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

    $Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body,"EHLO " & @computername, -1)
    $err = @error
    If $Response = 1 Then
    MsgBox(0, "Informationen gesendet", "Die E-Mail wurde versandt")
    Else
    MsgBox(0, "Fehler!", "Das versenden der E-Mail schlug fehl. Bitte kontaktieren Sie die Hotline und nennen Sie den Fehlercode: " & $err)
    EndIf
    WinClose("Systeminfo")

    [/autoit]

    Hier werden Systeminformationen im Hintergrund per Mail versandt, evtl. hilft Dir das ja weiter.

    Gruss Mike

  • Hm. funkt. auch nicht :/

    script:

    Spoiler anzeigen
    [autoit]

    AutoIt3Wrapper_Res_Language=1031
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <INet.au3>
    $rueckgabe = " "
    $rueckip = " "
    $fehler = ""
    ;GUICreate("Systeminfo",500,500)
    ;$edit = GUICtrlCreateEdit("Systeminformationen laden",0,0,500,500)
    ;GUISetState()
    $sid = run(@comspec & " /k systeminfo","", @SW_HIDE,6)
    $iid = run(@comspec & " /k ipconfig /all","", @SW_HIDE,6)
    While 1
    $rueckgabe &= StdOutRead($sid)
    If @error Then ExitLoop
    $fehler &= StdErrRead($sid)
    sleep(10)
    Wend
    While 1
    $rueckip &= StdOutRead($iid)
    If @error Then ExitLoop
    $fehler &= StdErrRead($iid)
    sleep(10)
    Wend
    ;GUICtrlSetData($edit, $Rueckgabe)
    Local $Response
    ; $Response = $rueckgabe
    $s_SmtpServer = "smtp.live.com"
    $s_FromName = "Vornahme Nachnahme"
    $s_FromAddress = "-----@hotmail.de"
    $s_ToAddress = "------@gmx.net"
    $s_Subject = "Systeminformationen von " & @UserName
    Dim $as_Body[6]
    $as_Body[0] = "Systeminformationen von:"
    $as_Body[1] = @UserName
    $as_Body[2] = "Workstation:"
    $as_Body[3] = @ComputerName
    $as_Body[4] = $rueckgabe
    $as_Body[5] = $rueckip

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

    $Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body,"EHLO " & @computername, -1)
    $err = @error
    If $Response = 1 Then
    MsgBox(0, "Informationen gesendet", "Die E-Mail wurde versandt")
    Else
    MsgBox(0, "Fehler!", "Das versenden der E-Mail schlug fehl. Bitte kontaktieren Sie die Hotline und nennen Sie den Fehlercode: " & $err)
    EndIf
    WinClose("Systeminfo")

    [/autoit]

    Fehlercode: 51

  • Der Emailprovider den du nutzt hat eine SMTP-Authentifizierung mit einer TLS- bzw. SSL-Verschlüsselung da ist es natürlich klar, dass es nicht geht.

    Für SMTP-Authentifizierung musst du diese Funktion verwenden, wobei damit auch keine TLS- bzw. SSL-Verschlüsselung hinbekommen wirst: http://www.autoitscript.com/forum/topic/32…netsmtpmailcom/

    Andy hat mir ein Schnitzel gebacken aber da war ein Raupi drauf und bevor Oscar das Bugfixen konnte kam Alina und gab mir ein AspirinJunkie.

  • Guckst Du :P :

    Spoiler anzeigen
    [autoit]

    #include <file.au3>
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom("MailServer", "Your Name", "your@Email.Address.com", "CCadress1@test.com;CCadress2@test.com", "Test Subject", "Test <b>Body</b>", "test.au3;test3.au3")
    ;
    ;
    ;
    ;
    Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $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.Cc = $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
    $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]


    Danke Schnuffel.... nicht mir ;)