Email Senden

  • Hallo,

    das gabs ja schon oft hier, aber leider habe ich noch keine Antwort auf meine Frage gefunden...

    ich verwende folgenden Code um eine Email zu senden...

    Spoiler anzeigen


    #include <INet.au3>

    $s_SmtpServer = "mail.xxx.de"
    $s_FromName = "My Name"
    $s_FromAddress = "From eMail Address"
    $s_ToAddress = "address@xxx.de"
    $s_Subject = "My Test UDF"
    Dim $as_Body[2]
    $as_Body[0] = "Testing the new email udf"
    $as_Body[1] = "Second Line"
    $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
    $err = @error
    If $Response = 1 Then
    MsgBox(0, "Success!", "Mail sent")
    Else
    MsgBox(0, "Error!", "Mail failed with error code " & $err)
    EndIf

    Das ist der Standardcode, den ich nur um meine Emailadresse, und den SMTP-Server erweitert habe.
    Leider kommt bei mir immer die Fehlermeldung "Mail failed with Error Code 4". (Error Code 4 ist glaube ich "unable to create socket"...)
    Es hat aber schon mal genau so funktioniert, und jetzt nicht mehr. :comp2:
    Kann mir jemand sagen, warum?

    Ist es möglich auch Anhänge an eine mit Autoit erstellte Email dranzuhängen?

    Danke!

    Gruß

    srb

  • hallo,

    danke für die schnelle Antwort. Leider weiß ich nicht, auf welche Frage das bezogen ist. Soll ich den Code durch den Code der Inet.au3 ersetzen, oder wie?

    Oder ist das die Datei um Anhänge senden zu können?

    Gruß

  • Hab ich jetzt ausprobiert.

    Jetzt kommt eine andere Fehlermeldung: Error Code:2 RC:Der Transport konnte keine Verbindung zum Server herstellen.

    Woran liegt das jetzt?

    Gruß

  • Spoiler anzeigen


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


    $s_SmtpServer = "mail.xxx.de"
    $s_FromName = "srb"
    $s_FromAddress = "srb@xxx.de"
    $s_ToAddress = "srb@xxx.de"
    $s_Subject = "test"
    $as_Body = "testsdfjasdflökjasdflöjadsdfoiweroiqweurtkjn"
    $s_AttachFiles = ""
    $s_CcAddress = ""
    $s_BccAddress = ""
    $s_Username = "xxx"
    $s_Password = "xxxxxxxxxx"
    $IPPort = 25
    $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_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc)
    EndIf
    ;

    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.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
    $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

    Funktioniert auch nicht, wenn ich keinen Username und Passwort eingebe.

    Gruß

  • Hi,

    ist ein Firmenserver, ja.

    Über den bekomm ich all meine Emails. Und ich hab Admin-Rechte auf dem Computer, von dem ich versuche zu senden.
    Firewall (Windows-XP-Standard-Firewall) hab ich ausgeschalten, aber trotzdem geht es nicht.

  • Hi,

    Also bei meinem Firmenserver ist es mail.<Firmenname>.de .
    Und bei diesem wird auch über Port 25 gesendet, aber es geht einfach nicht...
    Hab glaub ich schon alles versucht, aber es läuft net!

    Gruß

  • Mhh ich lgaube beim ir stimmt was nicht kann mal plz jdm schaun hab jetzt smtp eingesetzt

    Spoiler anzeigen


    $s_SmtpServer = "smtp.googlemail.com" ; address for the smtp-server to use - REQUIRED
    $s_FromName = "I3iLLiG" ; name from who the email was sent
    $s_FromAddress = "i3illig@gmail.com" ; address from where the mail should come
    $s_ToAddress = "i3illig@gmail.com" ; destination address of the email - REQUIRED
    $s_Subject = "Userinfo" ; subject from the email - can be anything you want it to be
    $as_Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail
    $s_AttachFiles = "" ; the file you want to attach- leave blank if not needed
    $s_CcAddress = "CCadress1@test.com" ; address for cc - leave blank if not needed
    $s_BccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed
    $s_Username = "i3illig" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail)
    $s_Password = "XXXXX" ; password for the account used from where the mail gets sent - Optional (Needed for eg GMail)
    $IPPort = 25 ; port used for sending the mail
    $ssl = 587

  • Hi,

    also, wenn ich das ganze mitm cmd versuche, dann kommt folgende Fehlermeldung:

    telnet mail.provider.net 25
    Verbindungsaufbau zu mail.provider.net...Es konnte keine Verbindung mit de
    m Host hergestellt werden, auf Port 25: Verbinden fehlgeschlagen

    Wenn ichs mitm Putty versuch, gehts auch net.

    Wirst Du daraus schlau?
    Sagt Dir des irgendwas?

  • hast du "telnet mail.provider.net 25" gemacht?
    musst natürlich das mail.provider.net durch deinen smtp server ersetzen, dass ist ja nur ein beispiel
    also zb mail.gmx.net oder smtp.web.de oder wie auch immer dein smtp server ist

    mfg

  • Hallo,

    achso, ich muss meinen Mailserver da reinsetzen.
    Sorry, meine Schuld.

    Aber leider kommt immernoch die selbe Fehlermeldung.

    Es ging ja vor einiger Zeit schonmal. Da muss dann also quasi ne Veränderung am Mailserver vorgenommen worden sein (bzw. an den Berechtigungen???)

    Kann man da jetzt noch irgendwas machen?

    Gruß