Problem | Inhalt der Inpubox per E-Mail versenden

  • Hallo liebe Gemeinde,

    ich bin gerade total am verzweifeln... Ich versuche schon seit paar Tagen fieberhaft die Inhalte einer Inputbox an meine E-Mail zu senden, doch leider funktioniert das überhaupt nicht. :thumbdown:
    Wenn ihr so nett seid, und mal rüberguckt. :) (bin leider ein totaler Anfänger)


  • Der SMTP-Port von Web.de ist nicht 25, wie kommst du überhaupt darauf? https://hilfe.web.de/sicherheit/ssl.html
    Außerdem musst du noch SSL aktivieren. Ich nehme mal an du hast die UDF einfach zerstückelt um es 0815mäßig nutzen zu können.

    Lass lieber die UDF wie sie ist und call die Funktion, das ist sicherer als dein Versuch.

    _InetSmtpMailCom
    [autoit]

    ;
    ;##################################
    ; Include
    ;##################################
    #Include<file.au3>
    ;##################################
    ; Variables
    ;##################################
    $SmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED
    $FromName = "Name" ; name from who the email was sent
    $FromAddress = "your@Email.Address.com" ; address from where the mail should come
    $ToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED
    $Subject = "Userinfo" ; subject from the email - can be anything you want it to be
    $Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail
    $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
    $CcAddress = "CCadress1@test.com" ; address for cc - leave blank if not needed
    $BccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed
    $Importance = "Normal" ; Send message priority: "High", "Normal", "Low"
    $Username = "******" ; username for the account used from where the mail gets sent - REQUIRED
    $Password = "********" ; password for the account used from where the mail gets sent - REQUIRED
    $IPPort = 25 ; port used for sending the mail
    $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS
    ;~ $IPPort=465 ; GMAIL port used for sending the mail
    ;~ $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

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

    ;##################################
    ; Script
    ;##################################
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
    EndIf
    ;
    ; The UDF
    Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $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])
    ;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
    If FileExists($S_Files2Attach[$x]) Then
    ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
    $objEmail.AddAttachment($S_Files2Attach[$x])
    Else
    ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
    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
    If Number($IPPort) = 0 then $IPPort = 25
    $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
    ; Set Email Importance
    Switch $s_Importance
    Case "High"
    $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
    Case "Normal"
    $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
    Case "Low"
    $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
    SetError(2)
    Return $oMyRet[1]
    EndIf
    $objEmail=""
    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]
  • Vielen Danke für deine rege Beteiligung, jedoch erhalte ich immer nachdem icn das Script gestartet habe eine Fehlermeldung:

    "Error code:2 Descritption:Der Server hat die Absenderadresse zurückgewiesen. Die Serverantwort lautet: 530 Must issue a STARTTLS command first"

    Irgendwelche Lösungen für das Problem bekannt?

  • Ich habe mir mal aus Spaß folgenden Script aus dem Internet kopiert, selbst dort erhalten ich den Fehler X(

  • Hallo Arah,

    Warnung: Hier kommt ein denkbar schlechter, aber gut gemeinter Beitrag.

    Denkbar schlecht, weil ich eine UDF nutze, sie nicht anhänge und sie nur bruchstückhaft vorführe. Das sind nur die Mindestangaben. Mehr Info hast du, wenn du dir die UDF mal ansiehst..

    Ich nutze die _INetSmtpMailCom.au3, die du dir noch laden müsstest. Da gibt es auch ein richtiges Fehlerhandling, das dir mehr Infos bereitstellt. Ich habe hier einfach mal eine Errorprüfung eingefügt, damit du eine Rückmeldung erhältst. Die Daten habe ich einfach übernommen. Da musst du schon die richtigen Werte finden.

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <ComboConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <INet.au3>

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

    #include <_INetSmtpMailCom.au3>

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

    $Form1 = GUICreate("E-Mail senden", 301, 161, 191, 123)
    $Input1 = GUICtrlCreateInput("Text", 8, 8, 273, 21)
    $Button1 = GUICtrlCreateButton("Senden!", 56, 128, 171, 25)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    Global $oMyRet[2]
    $SmtpServer = "smtp.web.de"
    $FromName = "Ich__"
    $FromAddress = "Absender@web.de"
    $ToAddress = "___email@web.de"
    $Subject = "Betreff ist: Dies ist ein Test"
    $AttachFiles = ""
    $CcAddress = ""
    $BccAddress = ""
    $Importance = "Normal"
    $username = "___email@web.de"
    $Password = "_passwort"
    $IPPort = 587
    $ssl = 0
    $Body = GUICtrlRead($Input1)
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $username, $Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "", "Fehler")
    Else
    MsgBox(0, "", "OK")
    EndIf
    EndSwitch
    WEnd

    [/autoit]

    Grüße autoiter

  • Vielen Danke für deine Antwort!
    Dein Code ist für mich gut überschaubar und leicht zu verstehen als Anfänger :thumbup:
    Jedoch besteht noch folgendes Problem: wo kann ich mir die "_INetSmtpMailCom.au3" herunterladen / wo & füge ich diese ein.

    edit: Habe soeben die "_INetSmtpMailCom.au" vom Post #2 in meinem include Ordner kopiert. Nun startet das Script. Bekomme aber immer folgende Fehlermeldung: "### COM Error ! Number: 80020009 ScriptLine: 91 Description:Der Server hat die Absenderadresse zurückgewiesen. Die Serverantwort lautet: 530 Must issue a STARTTLS command first"

    3 Mal editiert, zuletzt von Arah (2. März 2015 um 20:22)

  • Suche einfach mal mit der Suchmaschine deiner Wahl nach der UDF. Du wirst sie im englischen Forum finden.

    Die UDF gehört dann in den Include-Ordner deiner Autoit Installation oder einfach in das Verzeichnis deines Skripts. Dann bindest du es aber so ein: #include "_INetSmtpMailCom.au3>"

    Ich bin gerade wieder unterwegs, daher wiederum die knappe Antwort. Wenn noch Fragen auftauchen, melde dich einfach.

    Grüße autoiter

  • Das Einfügen der _INetSmtpMailCom.au3 hat geklappt. Nun startet das Script auch, jedoch bekomme ich kurz nach dem Starten diese Fehlermeldung:
    Error code:2 Description: Der Transport konnte keine Verbindung zum Server herstellen.

  • Echt? Wo kommt denn diese Meldung her? Hast du das Skript bearbeitet?

    Wenn nicht, führst du das falsche Skript aus. Hier gibt es gar keine detaillierte Rückmeldung, sondern nur eine Messagebox mit Fehler, oder OK. :D

    Grüße autoiter

  • Ich erhalte die MsgBox mit "Fehler" und direkt wenn ich das Script startet erhalte ich auch direkt eine MsgBox mit den Error code:2
    Verändert habe ich nur die ganzen Adressen, Passwort, etc.

  • Lösche mal das Global '$oMyRet[2]', denn das war unnötig.

    Führ das nochmal aus. Bekommst du mit genau diesem Sktipt die zweite Fehlermeldung? Das verstehe ich nicht.

    Ich habe das Skript eben mal mit meinen gmx Daten ausprobiert. Da hat es sofort funktioniert..

    Schalte vielleicht testweise mal deine Firewall ab, oder so. Das Skript tut mit den richtigen Daten nämlich, was es soll.

    Grüße autoiter

  • $oMyRet[2] entfernt + firewall ausgeschaltet, erhalte immer noch die Fehlermeldungen. Ich würde es mal gerne mit meinem gmx Konto versuchen, wie lautet dort der SmtpServer, IPPort, ssl?

  • Die Daten sind frei verfügbar. Google einfach mal nach GMX smtp.

    Falls du das nicht hinbekommst. Hier habe ich eine wegwerfadresse für dich. Da kannst du dich einloggen und das Passwort ändern. Dann gehört die Adresse dir. Logge dich bei ok.de mit den Daten ein, und sende eine Mail mit dem Skript. Ich habe das eben zweimal gemacht.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <_INetSmtpMailCom.au3>

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

    $Form1 = GUICreate("E-Mail senden", 301, 161, 191, 123)
    $Input1 = GUICtrlCreateInput("Text", 8, 8, 273, 21)
    $Button1 = GUICtrlCreateButton("Senden!", 56, 128, 171, 25)

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

    $SmtpServer = "mail.ok.de"
    $FromName = "Tester"
    $FromAddress = "wegwerfadresse2@ok.de"
    $ToAddress = "wegwerfadresse2@ok.de"
    $Subject = "Eine Testmail!"
    $AttachFiles = ""
    $CcAddress = ""
    $BccAddress = ""
    $Importance = "Normal"
    $username = "wegwerfadresse2@ok.de"
    $Password = "123Test123"
    $IPPort = 465
    $ssl = 1

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

    GUISetState(@SW_SHOW)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1

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

    $Body = GUICtrlRead($Input1)
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $username, $Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "", "Fehler")
    Else
    MsgBox(0, "", "OK")
    EndIf
    EndSwitch
    WEnd

    [/autoit]

    Ich habe auch mal die unnötigen includes entfernt. Wahrscheinlich hast du die aus deinem größeren Skript, oder? Hier sind sie aber unnötig.

    Grüße autoiter