E-MAil versenden

  • nabend alle zu sammen,

    hatte schon eine weile nix mehr mit Autoit gemacht. Nun muss ich etwas machen und komme nícht recht vorwärts. Hier mein Code aus dem Forum.

    Spoiler anzeigen
    [autoit]

    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_Outfile=\Mail.exe
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <INet.au3>
    #include <date.au3>

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

    ;Hier kommt die Registry Abfrage nach dem Schlüssel den HeiWoMa entdeckt hat. Gibt es den Schlüssel nicht ($Outlookexist =""), dann ist auch kein ;Outlook auf dem System installiert.
    $Outlookexist = RegRead("HKEY_CLASSES_ROOT\msgfile\shell\open\command", "command")
    $file = "C:\ADTG\Datensicherung\test.zup"
    ;Hier sieht man das die Variabe leer zurückgekommen ist, also kein Outlook installiert.
    ;E-Mail wird über den Standard E-Mail client z.B.OE versendet.
    $var = IniReadSection("H:\NAV\AMFA.ini", "HVP")
    $vas = IniReadSection("H:\NAV\AMFA.ini", "Mail")

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

    If FileExists("H:\NAV\Thomas\*.csv") Then
    CreateMailItem()
    EndIf
    ;
    Func CreateMailItem()
    Local $olMailItem = 0
    Local $olFormatRichText = 2
    Local $olImportanceNormal = 2
    $oOApp = ObjCreate("Outlook.Application")
    $oOMail = $oOApp.CreateItem($olMailItem)

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

    With $oOMail

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

    For $y = 1 To $vas[0][0]
    MsgBox(0,"","H:\NAV\Thomas\" & StringRight($var[$y][1], 7) & ".csv" & ' ' & $vas[$y][1],10)
    .To = ($vas[$y][1])
    .BCC = ("")
    .Subject = "Vertriebspartner Report"
    .Body = ":-)"
    .BodyFormat = $olFormatRichText ;Diese Funktion geht ab Outlook 2003, auskommentiert für die Outlook 2000 Kompabilität

    .Attachments.Add ("H:\NAV\Thomas\" & StringRight($var[$y][1], 7) & ".csv")

    .Importance = $olImportanceNormal
    .Display
    ;.Send ;Die Send Funktion ist wegen den Outlook Sicherheitsrichtlinien ausgeschaltet.
    Sleep(500)
    Send("!s")
    Sleep(10000)
    Next

    EndWith

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

    EndFunc ;==>CreateMailItem

    [/autoit]

    Die abgefragte Ini besteht aus zweit Section. In der ersten steht der Dateianhang in der zweiten die Mailadressen. Meine Kontrollbox zeigt das mein Weg der richtige ist. Doch leider bekomme ich eine Fehlermeldung während des zweiten Durchlauf der Schleife.
    Fehlermeldung:
    D:\Programme\AutoIt3\Include\MAil_Outlook.au3 (31) : ==> The requested action with this object has failed.:
    .To = ($vas[$y][1])
    .To = ($vas[$y][1])^ ERROR

    Hat wer ne Idee woran es liegt?

    MFG ThomasB

    MFG ThomasB

    *
    Ich lese viel und gerne (und wenn ich alle Mahnungen durch habe, schmeiße ich sie weg)
    *

  • Benutzt doch einfach die Funktion, die brauch auch kein Outlook:

    Spoiler anzeigen
    [autoit]

    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "")
    $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 $ex = 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") = 25
    ;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
    ;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]

    Beispiel:

    Spoiler anzeigen
    [autoit]

    ;~ Greek

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

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

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

    Global $oMyRet[2]
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Email versender", 396, 294, 1153, 185)
    $Input1 = GUICtrlCreateInput("", 8, 40, 121, 21)
    $Input2 = GUICtrlCreateInput("", 248, 40, 121, 21)
    $Label1 = GUICtrlCreateLabel("Mail sever: Für http://www.web.de ist er smtp.web.de ", 8, 16, 229, 17)
    $Label2 = GUICtrlCreateLabel("Name des Absenders", 248, 16, 105, 17)
    $Label3 = GUICtrlCreateLabel("Absender email addresse", 8, 72, 122, 17)
    $Input3 = GUICtrlCreateInput("", 8, 96, 121, 21)
    $Input4 = GUICtrlCreateInput("", 248, 96, 121, 21)
    $Label4 = GUICtrlCreateLabel("Empfänger email addresse", 248, 72, 128, 17)
    $Input5 = GUICtrlCreateInput("", 8, 152, 121, 21)
    $Label5 = GUICtrlCreateLabel("Betreff", 8, 128, 35, 17)
    $Label6 = GUICtrlCreateLabel(" Text ", 248, 128, 34, 17)
    $Input6 = GUICtrlCreateInput("", 248, 152, 121, 21)
    $Label7 = GUICtrlCreateLabel("Nochmal Absender email", 8, 184, 121, 17)
    $Input7 = GUICtrlCreateInput("", 8, 208, 121, 21)
    $Input8 = GUICtrlCreateInput("", 248, 208, 121, 21)
    $Label8 = GUICtrlCreateLabel("Passwort der Absender email", 248, 184, 140, 17)
    $Button1 = GUICtrlCreateButton("Email versenden", 152, 248, 100, 25, 0)
    $Button2 = GUICtrlCreateButton("Abbrechen", 312, 256, 75, 25, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    $rc = _INetSmtpMailCom(GUICtrlRead( $Input1),GUICtrlRead($Input2),GUICtrlRead($Input3), GUICtrlRead($Input4), GUICtrlRead($Input5), GUICtrlRead($Input6), "", "","", GUICtrlRead($Input7), GUICtrlRead($Input8))
    If @error then
    msgbox(0,"Error sending message","Error code:" & @error & " Description:" & $rc)
    EndIf
    Case $Button2
    Exit
    EndSwitch
    WEnd

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

    Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "")
    $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 $ex = 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") = 25
    ;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
    ;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]
  • Hallo Greek.

    Leider kommt folgende Meldung:
    C:\test\test.au3(65,31) : WARNING: $x: possibly used before declaration.
    $S_Files2Attach[$x]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\test\test.au3(65,31) : ERROR: $x: undeclared global variable.
    $S_Files2Attach[$x]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    C:\test\test.au3 - 1 error(s), 1 warning(s)

    Lieben Gruß,
    Alina

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Geheime Information: ;)
    OuBVU5ebLhHu5QvlnAyQB4A7SzBrvWulwL7RLl2BdH5tI6sIYspeMKeXMSXl

  • hi greek,

    da kommen wir dann aber schon zum zweiten Problem. Das Script habe ich auch schon aus probiert. Das das ganze als Dienst läuft kann dieses Script nicht so recht die Ini auslesen.

    MFG thomasB

    MFG ThomasB

    *
    Ich lese viel und gerne (und wenn ich alle Mahnungen durch habe, schmeiße ich sie weg)
    *

  • Continue Anyway anklicken ;)

    Du scheinst die Funktion wohl nicht zu mögen? [ gelöst ] MailVersand :rofl:

    Zitat

    hi greek,

    da kommen wir dann aber schon zum zweiten Problem. Das Script habe ich auch schon aus probiert. Das das ganze als Dienst läuft kann dieses Script nicht so recht die Ini auslesen.

    MFG thomasB

    Hm, versteh jetzt ehrlich gesagt nicht so was du meinst, warum kann das Script nicht Funktionieren wenn als Dienst läuft? ( Dienste sieht man doch nur bei den Prozessen nicht, oder? )

  • Hallo Thomasb,

    Code
    D:\Programme\AutoIt3\Include\MAil_Outlook.au3 (31) : ==> The requested action with this object has failed.:
    .To = ($vas[$y][1])
    .To = ($vas[$y][1])^ ERROR


    Die Fehlermeldung bedeuted meines Erachtens, dass im Array $vas[$y][1] in der zweiten Dimension kein gültiger Wert als Emailadressat enthalten ist. Am einfachsten wäre es aber du stellt eine CSV mit Testdaten ins Forum, dann kann man das besser austesten,

    mfg (Auto)Bert

  • hallo thomasb,

    was willst du denn genau mit dem script machen?
    wie versenden auch täglich reports, da werden bestimmte sachen aus einer ini gelesen!

    beispiel hier ohne ini.

    Spoiler anzeigen
    [autoit]


    #include <File.au3>
    #include <String.au3>

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

    ;#######################################################
    ; 1 tes mal als sms senden # Agent Performance Team BigService #
    ;#######################################################
    ;#########################
    ;pfad für anhang
    ;#########################

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

    $path1 = "\\server\Reporting1.pdf" ;"C:\Reporting\reporting2.pdf" ;attachments
    $mailto_01 = "user1@xxxxx.de;[email='user2@xxxx.de'][/email];user3@xxxx.de" ; mailempfänger
    MsgBox(0,"",$path1)
    ;#Include<file.au3>
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    ;##################################
    ; Include
    ;##################################
    ;#Include<file.au3>
    ;##################################
    ; Variables
    ;##################################
    $s_SmtpServer = "10.xx.xx.xx" ; address for the smtp-server to use - REQUIRED
    $s_FromName = "support@xxxxxx.de" ; name from who the email was sent
    $s_FromAddress = "support@xxxxxx.de" ; address from where the mail should come
    $s_ToAddress = $mailto_01 ; destination address of the email - REQUIRED
    $s_Subject = "report" ; 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 = $path1 ; the file you want to attach- leave blank if not needed
    $s_CcAddress = "" ; address for cc - leave blank if not needed
    $s_BccAddress = "support@xxxxx.de" ; address for bcc - leave blank if not needed
    $s_Username = "tool" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail)
    $s_Password = "xxxxxxxx" ; 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 = 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($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 & " Description:" & $rc)
    EndIf
    ;

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

    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

    [/autoit]

    vielleicht hilft dir das ja weiter!

    gruß gmmg

  • hi,

    ja das Script kenne ich und nutze es auch. Ich hatte aber schon erwähnt das das Script Probleme hat eine InI auszulesen wenn es als Dienst läuft.
    Es geht mir auch nur um den Fehler der auftritt, die MSGBOX die ich eingebaut habe gibt den Wert wieder, der ist ok, bevor der Fehler kommt.

    MFG ThomasB

    *
    Ich lese viel und gerne (und wenn ich alle Mahnungen durch habe, schmeiße ich sie weg)
    *

  • Hallo thomasb,

    füg einmal eine Consolenausgabe in dein Script dazu:

    [autoit]

    With $oOMail
    For $y = 1 To $vas[0][0]
    MsgBox(0,"","H:\NAV\Thomas\" & StringRight($var[$y][1], 7) & ".csv" & ' ' & $vas[$y][1],10)
    ConsoleWrite("TO:"&$vas[$y][1] & @CRLF) <----------------------- einbauen für Ausgabe in Scite-Console
    .To = ($vas[$y][1])

    [/autoit]


    Ich vermute, das die ArrayVariable keinen gültigen Email-Empfänger hat (siehe auch Post vom 02.0609)

    mfg (Auto)Bert

  • Hallo AutoBert,

    die Variable wird sauber übergeben.

    MFG ThomasB

    *
    Ich lese viel und gerne (und wenn ich alle Mahnungen durch habe, schmeiße ich sie weg)
    *

  • als dienst habe ich das selber noch nicht benutzt!

    bisher nur über taskmanager oder das script war generell gestartet und anfragen über while schleife!

    gruß gmmg