Zuviel Werbung? - > Hier kostenlos beim SPS-Forum registrieren

Results 1 to 4 of 4

Thread: Emails versenden mit WinCC flexible 2008

  1. #1
    Join Date
    03.12.2013
    Location
    Ansbach
    Posts
    157
    Danke
    0
    Erhielt 58 Danke für 30 Beiträge

    Default


    Zuviel Werbung?
    -> Hier kostenlos registrieren
    hab versucht mit WinCC flexible 2008 Emials zu versenden.
    Mit der integrierten Funktion von WinCC flexible hab ich das nicht geschafft.
    Jetzt hab ich mal nach VB-Script-Code gesucht um Emails zu versenden
    und hab folgendes auf technet.Microsoft gefunden.

    Irgendwie geht das aber trotzdem nicht.
    Die Diagnosemöglichkeiten sind irgendwie = 0!

    Hat das schon mal jemand gemacht und weis wie das geht.

    hier der VBS Code
    Code:
    'Create the objects require for sending email using CDO
    Set objMail = CreateObject("CDO.Message")
    Set objConf = CreateObject("CDO.Configuration")
    Set objFlds = objConf.Fields
    
    'Set various parameters and properties of CDO object
    objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort
    'your smtp server domain or IP address goes here such as smtp.yourdomain.com
    objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.yourdomain.com" 
    objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'default port for email
    'uncomment next three lines if you need to use SMTP Authorization
    objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your-username"
    objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your-password"
    objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic
    objFlds.Update
    objMail.Configuration = objConf
    objMail.From = "fromEmailAddress@yourdomain.com"
    objMail.To = "toEmailAddress@yourdomain.com"
    objMail.Subject = "Put your email's subject line here"
    objMail.TextBody = "Your email body content goes here"
    objMail.Send
    
    'Set all objects to nothing after sending the email
    Set objFlds = Nothing
    Set objConf = Nothing
    Set objMail = Nothing
    Reply With Quote Reply With Quote Emails versenden mit WinCC flexible 2008  

  2. #2
    Maagic7 is offline Erfahrener Benutzer
    Themenstarter
    Join Date
    03.12.2013
    Location
    Ansbach
    Posts
    157
    Danke
    0
    Erhielt 58 Danke für 30 Beiträge

    Default

    hab das jetzt noch etwas umgeschrieben und anderen Mailserver verwendet der SSL/TLS statt SARTTLS Verbindung verwendet,
    jetzt geht es!

  3. #3
    Maagic7 is offline Erfahrener Benutzer
    Themenstarter
    Join Date
    03.12.2013
    Location
    Ansbach
    Posts
    157
    Danke
    0
    Erhielt 58 Danke für 30 Beiträge

    Default

    Wer es testen will! Hier die modifizierte Version. So hat das bei mir funktioniert!

    Jetzt muss ich das nur noch in WinCC verbasteln.

    Code:
    ' =======================================================================================
     ' NAME: SendEmailMSG
     ' DESC: Sendet eine Email Nachricht
     ' DESC: nutzt das in Windows integrierte CDO.Message Object
     ' DESC: das sollte ab Windows XP funktionieren
     ' PARA(): 
     
     ' AUTOR:  S. Maag
     ' DATE:   14.01.2020
     ' CHANGE:
     ' =======================================================================================
    
    
    Dim Server_Address
    Dim Server_Port
    Dim Server_UseSSL  ' TRUE or FALSE
    Dim Server_MailUserName 
    Dim Server_MailPW
    
    Dim Mail_SendTo      ' Destination Mail Address
    Dim Mail_SendFrom     ' Send from Mail Address
    Dim Mail_Subject     ' Mail subject (Betreff)
    Dim Mail_Body        ' Mail text
    
    ' ----------------------------------------------------------------------
    ' Input here your Server datas
    ' ----------------------------------------------------------------------
    Server_Address = "smtp.kontent.com"  ' hier die korrekte SMTP Mail Server Adress eintragen
    Server_Port = 25  ' 25 or 465 or 587
    Server_UseSSL = True
    Server_MailUserName = "MyMailUserName"
    Server_MailPW = "MyMailAccount_Password"
    
    ' ----------------------------------------------------------------------
    ' Input here your Email datas
    ' ----------------------------------------------------------------------
    Mail_SendTo =     "Empfaenger Email Adresse"  
    Mail_SendFrom = "Sender Email Adresse"
    
    ' Betreff
    Mail_Subject =     "Automatic Mail"
    ' Text
    Mail_Body =     "senden automatischer Emails"
    
    ' ----------------------------------------------------------------------
    ' SMTP Remote Server configuration based on Microsoft technet articele
    ' https://gallery.technet.microsoft.com/VBScript-Visual-Basic-4376ac26
    ' using full name access to fields is more clear then the original
    ' microsoft code
    ' ----------------------------------------------------------------------
    Dim ObjSendMail
    Set ObjSendMail = CreateObject("CDO.Message")
    
    With ObjSendMail.Configuration.Fields       
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' SMTP over network
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =Server_Address
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = Server_Port
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = Server_UseSSL 'use SSL TRUE or FALSE
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 20
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") =Server_MailUserName
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") =Server_MailPW
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic clear text authentication
        .Update
    End With
    
    ' ----------------------------------------------------------------------
    '  configuration of the Email    
    ' ----------------------------------------------------------------------
    ObjSendMail.To = Mail_SendTo
    ObjSendMail.From = Mail_SendFrom
    
    ObjSendMail.Subject = Mail_Subject
    ' send plain Text Mail  
    ObjSendMail.TextBody = Mail_Body
    
    ' if you want to send a HTML Mail, use this command
    'ObjSendMail.HTMLBody = "this is the body"
     
    ObjSendMail.Send  ' send the Mail
        
    Set ObjSendMail = Nothing 
    
    MsgBox "SendMail Done!"

  4. #4
    Maagic7 is offline Erfahrener Benutzer
    Themenstarter
    Join Date
    03.12.2013
    Location
    Ansbach
    Posts
    157
    Danke
    0
    Erhielt 58 Danke für 30 Beiträge

    Default


    Zuviel Werbung?
    -> Hier kostenlos registrieren
    heute ist ein echt produktiver Tag, das kommt viel zu selten vor.
    Das Email Script geht auch aus WinCC heraus.

    Diese Script in WinCC flexible kopieren und die Übergabeparameter anlegen.
    Dann könnt ihr testen.

    Code:
    ' =======================================================================================
     ' NAME: SendEmailMSG (MsgSubject, MsgBody, Email_ID
     ' DESC: Sending an Email with the CDO.Message Object
     ' DESC: which is integrated in Windows since Win2k
     ' 
     ' PARA(MsgSubject):  Text for Mail Subject (=Betreff)
     ' PARA(MsgBody)   :  Mail Text
     ' PARA(Email_ID)  :  the ID of the Email Address to read it from an Array()
     '                      I use a WinCC flexible DropDown with the names of the
     '                    Service technican. His Email I read with the Script
     '                      Service_GetMailAddress(Email_ID)
     
     ' AUTOR:  S.Maag
     ' DATE:   14.01.2020    
     ' CHANGE:
     ' =======================================================================================
    
    
    Dim Server_Address
    Dim Server_Port
    Dim Server_UseSSL      ' TRUE or FALSE
    Dim Server_MailUserName 
    Dim Server_MailPW
    
    Dim Mail_SendTo      ' Destination Mail Address
    Dim Mail_SendFrom     ' Send from Mail Address
    Dim Mail_Subject     ' Mail subject (Betreff)
    Dim Mail_Body        ' Mail text
    
    ' ----------------------------------------------------------------------
    ' Input your Server datas here
    ' ----------------------------------------------------------------------
    Server_Address = "smtp.kontent.com"
    Server_Port = 25  ' 25 or 465
    Server_UseSSL = True
    Server_MailUserName = "Account User Name"
    Server_MailPW = "Password"
    
    ' ----------------------------------------------------------------------
    ' Input your Email datas here
    ' ----------------------------------------------------------------------
    Mail_SendTo =     Service_GetMailAddress(Email_ID)  ' Call Script to read Email Address
    Mail_SendFrom = "Email Adresse Absender"
    
    Mail_Subject =     MsgSubject
    Mail_Body =     MsgBody
    
    ' ----------------------------------------------------------------------
    ' SMTP Remote Server configuration based on Microsoft technet articele
    ' https://gallery.technet.microsoft.com/VBScript-Visual-Basic-4376ac26
    ' using full name access to fields is more clear then the original
    ' microsoft code
    ' ----------------------------------------------------------------------
    Dim ObjSendMail
    Set ObjSendMail = CreateObject("CDO.Message")
    
    With ObjSendMail.Configuration.Fields       
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' SMTP over network
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") =Server_Address
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = Server_Port
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = Server_UseSSL 'use SSL TRUE or FALSE
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 20 ' 20sec TimeOut
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") =Server_MailUserName
        .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") =Server_MailPW
        .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic clear text authentication
        .Update
    End With
    
    ' ----------------------------------------------------------------------
    '  configuration of the Email    
    ' ----------------------------------------------------------------------
    ObjSendMail.To = Mail_SendTo        ' Destination Email Address
    ObjSendMail.From = Mail_SendFrom    ' Sender Email Address
    
    ObjSendMail.Subject = Mail_Subject    ' Mail Subject (Betreff)
    ' send plain Text Mail  
    ObjSendMail.TextBody = Mail_Body    ' Mail Text
    
    ' if you want to send a HTML Mail, use this command
    'ObjSendMail.HTMLBody = "this is the body"
     
    ObjSendMail.Send  ' send the Mail
        
    Set ObjSendMail = Nothing 
    
    If Err.Number <> 0 Then
        ' Error occured
    End If
    
    ' MsgBox "SendMail Done!"  ' This is only for testing as direct VB-Script in Windows, withour WinCC flexible
    hier der Vollständigkeit halber das Script um die Emailadresse aus der Email_ID zu bestimmen.
    Diese als Funktion anlegen

    Code:
    ' =======================================================================================
     ' NAME: Servce_GetMailAddress
     ' DESC: gibt anhand der EmailAddressID die Emailadresse zurück
     ' DESC: die Email Adressen müssen entweder in einem Array oder
     ' DESC: auch einer Datei zur Verfügung gestellt werden.
     ' DESC: das Email Adress Array muss zur Einstellung der TextAuswahlliste 
     ' DESC: im Bild Service_Email passen!!!
      
     ' RET:  EmailAdress$ (EmailAddressID)
      
     ' AUTOR:  S. Maag
     ' DATE:   14.01.2020    
     ' CHANGE: 
     ' =======================================================================================
    
    
    Dim sTXT
    
    Select Case EmailAddressID
        Case 0  ' Techniker 1
            sTXT = "Techniker1@Frima.de"
            
        Case 1  ' Techniker 2
            sTXT = "Techniker2@Firma.de"
    End Select
    
    Service_GetMailAddress = sTXT
    Kann das mal jemand auf einem WinCE Panel testen.
    Das sollte auch in WinCC TIA funktionieren!

Similar Threads

  1. Replies: 5
    Last Post: 11.11.2017, 11:18
  2. Replies: 1
    Last Post: 26.09.2015, 13:38
  3. [Moeller MFD] Emails versenden
    By b0zzen in forum Sonstige Steuerungen
    Replies: 11
    Last Post: 27.02.2013, 08:57
  4. Replies: 2
    Last Post: 15.06.2010, 23:45
  5. Emails versenden mit BC9000??
    By TomCatShS in forum CODESYS und IEC61131
    Replies: 16
    Last Post: 25.10.2009, 10:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •