_INetSmtpMail Probelm

  • Moin zusammen,

    Ich möchte mit AutoIt eine Mail schicken und benutze dazu die Funktion:

    [autoit]

    _INetSmtpMail

    [/autoit]

    Sieht bei mir so aus :

    [autoit]

    Func email()
    $s_SmtpServer = "smtp.1und1.de"
    $s_FromName = "test"
    $s_FromAddress = "test@test.com"
    $s_ToAddress = "test@aol.com"
    $s_Subject = "test"
    Dim $as_Body[2]
    $as_Body[0] = "test1"
    $as_Body[1] = "test2"
    $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
    $err = @error
    If $Response = 1 Then
    MsgBox(0, "Success!", "E-Mail erfolgreich gesendet")
    Else
    MsgBox(0, "Error!", "E-Mail nicht erfolgreich gesendet. Error Code :" & $err)
    EndIf
    EndFunc

    [/autoit]

    Jetzt bekomme ich den ErrorCode 52 angezeigt. Welches ja heist :

    Zitat

    Funktion _INetSmtpMail@ERROR = 5x - Kann keine SMTP Session eröffnen. x zeigt die Indexnummer des letzen Befehls welcher an den SMTP Server übertragen wurde.

    Wenn ich in der Funktion nach schaue würde ich sagen das das dieser Bereich ist wo der Fehler auftritt

    [autoit]


    ; send header
    For $i_Count = 1 To UBound($s_Send) - 2
    If _SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then
    SetError(50 + $i_Count)
    Return 0
    EndIf
    Next

    [/autoit]

    Nur finde ich jetzt nicht genau raus was es ist. Sehe ich da irgendwas total falsch oder ists wieder so ein dummer kleiner Fehler ? Da reichen meine Kenntnisse nicht aus. Kann mir da einer helfen?

    P.S.: Hab gerade mal noch andere SMTP Server getestet. GMX = Errorcode 51, google = Errorcode 50

    2 Mal editiert, zuletzt von MrB (31. Januar 2010 um 23:56)

  • nutze doch diese, die is viel besser

    Spoiler anzeigen
    [autoit]


    ; Script Start - Add your code below here
    ;
    ;##################################
    ; Include
    ;##################################
    #include<file.au3>
    ;##################################
    ; Variables
    ;##################################
    $SmtpServer = "" ; address for the smtp-server to use - REQUIRED
    $FromName = "" ; name from who the email was sent
    $FromAddress = "" ; address from where the mail should come
    $ToAddress = "" ; destination address of the email - REQUIRED
    $Subject = "" ; 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 you want to attach- leave blank if not needed
    $CcAddress = "" ; address for cc - leave blank if not needed
    $BccAddress = "" ; address for bcc - leave blank if not needed
    $Importance = "" ; 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 $x = 0
    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

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

    ;
    ; 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(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
    If FileExists($S_Files2Attach[$x]) Then
    $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]
  • THX Sprenger120,

    Probiert aber naja nächstes Problem was garantiert an mir liegt ^^

    Ruf die so auf (includet ist sie):

    [autoit]


    Func email()
    $s_SmtpServer = "smtp.web.de"
    $s_FromName = "test"
    $s_FromAddress = "test@db.com"
    $s_ToAddress = "test@aol.com"
    $s_Subject = "test"
    $s_Username = "test"
    $s_Password = "test"
    $as_Body = "test"
    $Response = _INetSmtpMailCom ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_Username, $s_Password)
    $err = @error
    If $Response = 1 Then
    MsgBox(0, "Success!", "Mail sent")
    Else
    MsgBox(0, "Error!", "Mail failed with error code " & $err)
    EndIf
    EndFunc

    [/autoit]

    Und bekomme ErrorCode 1. Wenn ich Username und Password auf "" setze dann kommt Errorcode 2. Was mache ich falsch ?

  • du musst dich auch beim smtp server authifenzieren (bestimmt falsch geschrieben :S ) und deswegen pwd + username


    hier mal das bsp für gmx

    [autoit]


    $SmtpServer = "mail.gmx.net" ; address for the smtp-server to use - REQUIRED
    $FromName = "" ; name from who the email was sent
    $FromAddress = "DeineEmailAddresse@anbieter.de" ; address from where the mail should come
    $ToAddress = "empfänger@anbieter.de" ; destination address of the email - REQUIRED
    $Subject = "Ich bin der Titel der Email" ; subject from the email - can be anything you want it to be
    $Body = "Ich bin der inhalt" ; the messagebody from the mail - can be left blank but then you get a blank mail
    $AttachFiles = "" ; the file you want to attach- leave blank if not needed
    $CcAddress = "" ; address for cc - leave blank if not needed
    $BccAddress = "" ; address for bcc - leave blank if not needed
    $Importance = "" ; Send message priority: "High", "Normal", "Low"
    $Username = "deineemailaddresse@anbieter.de" ; username for the account used from where the mail gets sent - REQUIRED
    $Password = "deinPasswortfür deinen email account" ; 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

    [/autoit]
  • Also langsam bin ich am verzweifeln.

    Nochmal, so sieht´s bei mir aus :

    [autoit]

    Func email()
    ;~ _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)
    $s_SmtpServer = "smtp.de.aol.com"
    $s_FromName = "****"
    $s_FromAddress = "****@db.com"
    $s_ToAddress = "****@aol.com"
    $s_Subject = "****"
    $as_Body = "***"
    $s_AttachFiles = ""
    $s_CcAddress = ""
    $s_BccAddress = ""
    $s_Importance = "Normal"
    $s_Username = "****"
    $s_Password = "****"
    $IPPort = 587
    $ssl = 0

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

    $Response = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress , $s_BccAddress , $s_Importance, $s_Username, $s_Password, $IPPort, $ssl)

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

    $err = @error

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

    If $Response = 1 Then
    MsgBox(0, "Success!", "Mail sent")
    Else
    MsgBox(0, "Error!", "Mail failed with error code " & $err)
    EndIf
    EndFunc ;==>email

    [/autoit]

    Error gibt 2 zurück
    Die Funktion folgendes :

    Zitat

    ### COM Error ! Number: 80020009 ScriptLine: 90 Description: Der Transport konnte keine Verbindung zum Server herstellen.

    Script Line 90 der Funktion (fängt bei 90 an):

    [autoit]

    $objEmail.Send
    If @error Then
    SetError(2)
    Return $oMyRet[1]
    EndIf
    $objEmail = ""

    [/autoit]

    Bin am Ende und weis nicht weiter. Vielleicht hat ja einer ne Idee. Ach ja, FW ist aus.

  • Thx euch beiden.

    Zitat

    Wieso loggst du dich bei AOL mit einer db.com-Adresse ein?

    Habs dann auch mal mit einer AOL Adresse probiert. ErrorCode 2

    Zitat

    was ich noch vergessen habe
    du musst natürlich beim jewailgen smtp server registriert sein

    Schon klar :-). Bin ich auch. Noch irgendwelche Ideen ?

    P.S.: Benutze Win 7 64bit. Vielleicht deswegen ?

    Einmal editiert, zuletzt von MrB (31. Januar 2010 um 15:57)

  • Hab jetzt auch mal andere SMTP´s probiert googlemail,1&1 und web.de . Immer Errorcode 2. Kann mir einer sagen Was das genau heist:

    Zitat

    @ERROR = 2 - Kann TCP nicht starten

    So langsam hab ich keine Ideen mehr. Angepingt hab ich auch schon. Klappt bei allen wunderbar