SMTP Mail Doku v12 v1 0 en
SMTP Mail Doku v12 v1 0 en
SMTP Mail Doku v12 v1 0 en
http://support.automation.siemens.com/WW/view/en/46817803
Warranty and Liability
Note The Application Examples are not binding and do not claim to be complete
regarding the circuits shown, equipping and any eventuality. The application
examples do not represent customer-specific solutions. You are responsible for
ensuring that the described products are used correctly. These Application
Examples do not relieve you of your responsibility to use safe practices in
application, installation, operation and maintenance. When using these
application examples, you recognize that we cannot be made liable for any
damage/claims beyond the liability clause described. We reserve the right to
make changes to these Application Examples at any time and without prior
notice. If there are any deviations between the recommendations provided in this
application example and other Siemens publications e.g. catalogs the
contents of the other documents have priority.
We do not accept any liability for the information contained in this document.
Any claims against us based on whatever legal reason resulting from the use of
the examples, information, programs, engineering and performance data etc.,
described in this application example will be excluded. Such an exclusion will not
apply in the case of mandatory liability, e.g. under the German Product Liability Act
(Produkthaftungsgesetz), in case of intent, gross negligence, or injury of life, body
Siemens AG 2013 All rights reserved
Caution
The functions and solutions described in this entry are mainly limited to the
realization of the automation task. Please furthermore take into account that
corresponding protective measures have to be taken in the context of industrial
security when connecting your equipment to other parts of the plant, the enterprise
network or the Internet. Further information can be found under the Entry ID
50203404.
http://support.automation.siemens.com/WW/view/en/50203404
Table of Contents
Warranty and Liability ................................................................................................. 2
1 Automation Task ................................................................................................ 4
2 Automation Solution ......................................................................................... 5
2.1 Solution overview ................................................................................. 5
2.2 Description of the core functionality ..................................................... 6
2.3 Hardware and software components used........................................... 7
2.4 Alternative ............................................................................................ 8
3 Functional Mechanisms of this Application ................................................... 9
3.1 Program overview ................................................................................ 9
3.2 Functionality of FB PN_MAIL ............................................................. 10
3.2.1 Program details on block FB PN_MAIL .............................................. 10
3.2.2 Call interface of the PN_MAIL (FB490) .............................................. 11
3.2.3 Initialization/reset of FB PN_MAIL ..................................................... 15
3.2.4 Email transmission ............................................................................. 16
3.2.5 FB PN_MAIL (FB490): STATUS and SFC_STATUS.................... 16
4 Installation and Commissioning .................................................................... 20
Siemens AG 2013 All rights reserved
6 Appendix .......................................................................................................... 27
6.1 SMTP commands: Minimum command set ....................................... 27
6.2 SMTP connection process between client and server ....................... 27
6.3 Status and error messages of an SMTP server ................................. 29
7 Literature .......................................................................................................... 31
7.1 Bibliography........................................................................................ 31
7.2 Internet link specifications .................................................................. 31
7.2.1 Relevant RFCs ................................................................................... 32
8 History............................................................................................................... 32
1 Automation Task
Introduction
The growing degree of networking in the automation industry also increases the
demand for the exchange of messages beyond the limits of local area networks
(LANs). Already existing infrastructure, such as, for example, existing server
constellations are to be used for the exchange.
One possibility for such communications is the use of email services via the
Intranet/Internet. This makes it possible to use already existing IT infrastructures in
order to transmit messages from the production level directly with standard IT
services.
2 Automation Solution
2.1 Solution overview
Schematic layout
The following figure gives a schematic overview of the most important components
of the solution:
Figure 2-1
Intranet/
Internet
FB
Terminal device
PN_Mail
(PC, smartphone, )
Ethernet
Siemens AG 2013 All rights reserved
SMTP Server
FB
PN_Mail
S7-300/S7-400/WinAC
Copyright
The core of the automation solution is the FB PN_MAIL. It controls the sending of
emails via the SMTP server via the blocks of the open communication (OUC
blocks: TCON, TSEND, TRCV, TDISCON)
While the open communication blocks control the basic TCP/IP services,
FB PN_MAIL operates the higher-level email transmission services and
communicates with the mail server. The Internet standard SMTP (Simple Mail
Transfer Protocol) is used as a protocol.
Once the mail server has received the message, the email is considered sent by
the PLC. Further sending of the email via Intranet/Internet cannot be influenced by
the PLC.
Delimitation
This application does not include a description of TCP/IP communication basics or
the use of Simple Mail Transfer Protocols. Basic knowledge of these fields is
assumed or can be found in the documents listed in the appendix.
The application describes only the use and properties of the used communication
blocks. It is assumed that all other components are available, in particular a
correctly configured SMTP server. The configuration of these components is not
part of this application.
Note The open communication blocks TCON, TSEND, TRCV and TDISCON are used
for the TCP/IP communication. The configuration data for these blocks is defined
in the FB PN_MAIL block in the structure TCON_PAR.
Subject line
Priority
ASCII plain text and where necessary an email attachment
function blocks
46817803_SMTP_Mail_V12_DOKU_V1_0_en.pdf This document.
2.4 Alternative
Overview
The PN_Mail block included in this application is only intended for the use in the
hardware platforms listed in chapter 2.3.
In order to send mails as email client with the S7-CPUs, you have other options,
too.
S7-1200/S7-1500 CPUs
There are ready system blocks for S7-1200 and S7-1500 in the STEP 7 V12 library
(TM_Mail and TMAIL_C).
Instructions for the use of the two blocks can be found in the online help of the TIA
Portal.
S7-300/S7-400 CPs
The following CPs can also be configured as email client:
CP 343 -1 Advanced
CP343-1 IT
CP443-1 Advanced
Siemens AG 2013 All rights reserved
CP443-1 IT
Instructions for the use of communication processors as email client can be found
in the manuals of the communication processors used by you (e.g. for the CP343-1
Advanced (6GK7343-1GX31-0XE0) see
http://support.automation.siemens.com/WW/view/en/30564821
http://support.automation.siemens.com/WW/view/en/30564821 ).
Copyright
TCON
TSEND
FB1 FB PN_Mail
OB1
(FB1) (FB490)
TRECV
TDISCON
Siemens AG 2013 All rights reserved
FB PN_MAIL.
You can freely adjust the numbers of the individual blocks for your user program.
All communication with the SMTP server takes place via FB PN_MAIL.
Except for serving as a wrapper for FB PN_MAIL, the only function of FB 1 is to
intermediately store the pending error codes (STATUS, SFC_STATUS, see 0) in
another variable for only one cycle in the event of an error, so that they are
available for later analysis.
Syntax checks
For performance reasons, the syntax of transferred email addresses is not checked
for correctness. This applies particularly to the parameters TO_S, CC and FROM
listed below.
Copyright
A positive edge FALSE TRUE starts a new email transmission. In all other
cases an already started transmission is continued or if no transmission job is to
be processed the block returns straight away. (However, see also COM_RST).
For details on the transmission process, see .
Note Please note that after the watchdog timeout, the FB still needs time to disconnect
the connection. This means that you should continue the FB calls, even in case
of a watchdog timeout with a respective error value.
The parameter starts with the TO: keyword, followed by a space and the email
address between pointed brackets, for example: TO: < mail@example.com >,.
The specification is completed with a comma.
digits for the hours and two additional digits for the minute difference from UTC.
During the standard time period, Germany is in zone +0100, during the daylight
saving time period the country is in zone +0200.
If no SENDER_TIMEZ is transferred or if the length of the transferred string differs
from 5 characters, the FB takes on the default value +0100.
There is no check for implausible values (e.g., +3599).
1
The time at which the mail is transferred to FB PN_MAIL is valid.
2
MIME = "Multi Purpose Internet Mail Enhancement"
Connection ID, which is used by the OUC (Open User Communication) blocks.
Make sure that this ID on the PLC is not yet assigned (for example, in Netpro or
through other communication blocks).
transferred to the FB is not accepted to the instance data block of the FB each time
3
FB PN_MAIL is called. Instead, the following parameters are updated in the
instance DB only when the FB is called with COM_RST = TRUE:
USERNAME
PASSWORD
CC
TEXT
ATTACHMENT
DEVICE_ID
3
Since the processing of a mail transmission job covers several CPU cycles, the risk of data
inconsistencies would be high if, for example, the content of the buffer for texts or attachments
would be changed in the middle of the mail transmission.
Transmission procedure
The mail transmission is triggered by a positive edge at the REQ input of the FB
PN_MAIL (FB490).
While the email is being transmitted, BUSY has the value TRUE and STATUS or
SFC_STATUS indicate the relevant current values of FB PN_MAIL or system
blocks called by this FB.
Once the transmission has been completed, BUSY returns to FALSE, and DONE
and if necessary ERROR are set.
The following table shows an overview of possible combinations of the BUSY,
DONE and ERROR values:
Table 3-2
BUSY DONE ERROR State.
0 0 0 No send job is pending
1 -- -- Send job is being processed
0 1 0 Send job successfully completed
0 0 1 Send job has been aborted with an error message (see
values of STATUS and SFC_STATUS)
Siemens AG 2013 All rights reserved
The following table provides an overview of the values the STATUS and
SFC_STATUS parameters can take on. In addition, it provides information on how
to respond to errors that have occurred.
Table 3-3
Return value Return value Explanation Notes
STATUS SFC_STATUS
(W#16#...) (W#16#...)
0000 Execution of FB PN_MAIL has Completing FB PN_MAIL
been completed without error without error does not
(if DONE = TRUE). automatically mean that the
sent mail arrives at the
intended recipient (see 3.2.4)
7001 FB PN_MAIL is active (BUSY = 1).
7002 7002 FB PN_MAIL is active (BUSY = 1).
z=5 TEXT
z=6 ATTACHMENT
z=7 USERNAME
z=8 PASSWORD
8010 xxxx Error while establishing the COM_RST may not have
connection. been set after loading the
instance DB, see 3.2.3.
Also check the specified
connection parameters and
Copyright
Note
The installation and commissioning is described with a CPU 315-2 PN/DP. You can
also use any other PLC, listed in 2.3.
Figure 4-1
SMTP Server
PC
CPU 315-2 PN/DP
LAN/WAN/
Ethernet Internet
Copyright
46817803_SMTP_Mail_V12_CODE_V1_0.zip
file onto your engineering station and unzip the
folder.
2. Double click the 46817803_SMTP.ap12 icon in
the program folder.
The project now opens in TIA V12.
3. Click onto CPU S7-300 and download the user
program into the CPU via Online > Download
and reset PLC program.
Copyright
4. Now you can monitor the individual variables How to send an email to the SMTP server is
and the state of the CPU. described in chapter 5.
NOTE For details on configuring your Internet connection, please refer to the
documentation of your Internet service provider (ISP) and follow the relevant
instructions!
NOTE Make sure that your selected SMTP server is configured so that it accepts one of
the authentication methods supported by FB PN_MAIL (see 0)!
Siemens AG 2013 All rights reserved
Copyright
attachment to the email. Make sure that the default value of the attachment (no
attachment is sent) is NULL.
6. Download the configuration to the CPU.
Copyright
12. To send another email, reset FB1_DB.Req to FALSE and then back to TRUE.
(The mail transfer is triggered by a rising edge of FB1_DB.Req.)
13. If you are changing the receiver addresses between two mails, repeat step 0 and
thus carry out a block initialization.
Your values for USERNAME and PASSWORD probably differ from the values
shown here and must match the accounts that have been set up on the SMTP
server you are using.
A number of parameters for FB PN_MAIL are not taken from the DB Param_DB,
but are transmitted directly, amongst others, the REQ input as well as the IP
address of the SMTP mail server (ADR_MAIL_SERVER).
Figure 5-2
Siemens AG 2013 All rights reserved
Copyright
The program section following the call of FB 1 is used to permanently freeze error
messages that are normally only present for one cycle and that would otherwise
have been overwritten after the next CPU cycle: If an error occurred (ERROR_FB),
the 'Error' flag is set and the values for STATUS and SFC_STATUS are copied into
the variables FB1_DB.Status and FB1_DB2.sfc_Status.
Figure 5-3 shows Email watch table while processing an email transmission job.
Figure 5-3: "Email" watch table (section)
The meaning of the entries of the watch table in detail (for further details of the
individual parameters of FB PN_MAIL see also 3.2.2):
Table 5-2
Siemens AG 2013 All rights reserved
6 Appendix
6.1 SMTP commands: Minimum command set
The command set that SMTP servers must understand is limited. The minimum
implementation is already possible with only eight different commands:
Table 6-1: Minimum command set for an SMTP server
SMTP command Description
HELO/EHLO HELO or EHLO starts the SMTP session and identifies the client to the server.
(Hello/Extended
Hello)
MAIL MAIL initiates the email transmission and also provides the senders address.
RCPT (Recipient) RCPT indicates the address of one or several recipients. This command can be
executed multiple times.
DATA DATA initiates the transmission of the email message. The end of the email
message is marked by CRLF.CRLF.
RSET (Reset) RSET aborts an already initiated email transmission. The connection between
client and server remains established.
VRTY (Verify) The recipients address can be verified using VRFY.
Siemens AG 2013 All rights reserved
Table 6-2: SMTP dialog process between client and server when sending an email without authentication
Client Server Explanation
220
smtp.example.co
m ESMTP Postfix
HELO If at this point the client sends EHLO instead of HELO, the
relay.example.org server will respond with a list of supported authentication
methods and an authentication dialog can start.
250 Hello
relay.example.org,
I am glad to meet
you
MAIL Account of the sender of the message. If respective
FROM:<bob@exam authentication methods are used, this account must exist
ple.org> on the server.
Cc:
theboss@example.c
om
Date: Tue, 15 Jan Date and time of the message as provided by the client.
2008 16:02:43 -0500 PRIORITY and IMPORTANCE fields can be inserted here.
Subject: Test
message
Hello Alice.
Copyright
This is a test
message with 5
header fields and 4
lines in the message
body.
Your friend,
Bob
. Line with only one decimal point as the end of the email
body.
250 Ok: queued Acknowledgement of the server.
as 12345
QUIT
221 Bye
250 OK, queuing for node node started. Requested mail action okay, completed.
251 OK, no messages waiting for node node. User not local, will forward to forwardpath.
252 OK, pending messages for node node started. Cannot VRFY user (e.g., info is not local), but
will take message for this user and attempt delivery.
253 OK, messages pending messages for node node started.
354 Start mail input; end with <CRLF>.<CRLF>.
355 Octet-offset is the transaction offset.
421 Domain service not available, closing transmission channel.
432 A password transition is needed.
4
450 Requested mail action not taken: mailbox unavailable. ATRN request refused.
4
ATRN: Authenticated Turn, a process for mail transmission with the use of dynamic IP
addresses. Also called ODMR (On-Demand Mail Relay).
Status
code English description
451 Requested action aborted: local error in processing. Unable to process ATRN request now.
452 Requested action not taken: insufficient system storage.
453 You have no mail.
454 TLS not available due to temporary reason. Encryption required for requested authentication
mechanism.
458 Unable to queue messages for node node.
459 Node node not allowed: reason.
500 Command not recognized: command Syntax error.
501 Syntax error, no parameters allowed.
502 Command not implemented.
503 Bad sequence of commands.
504 Command parameter not implemented.
521 Machine does not accept mail.
530 Must issue a STARTTLS command first. Encryption required for requested authentication
mechanism.
534 Authentication mechanism is too weak.
538 Encryption required for requested authentication mechanism.
Siemens AG 2013 All rights reserved
7 Literature
7.1 Bibliography
This list is not complete and only represents a selection of relevant literature.
Table 7-1
Topic Title
/1/ STEP7 Automating with STEP7 in AWL and SCL
Hans Berger
Publicis Publishing
ISBN 978-3-89578-412-5
/2/ Open Open Communication via Industrial Ethernet, Siemens
communication documentation A5E00711636-01
Topic Title
\1\ Link to this document http://support.automation.siemens.com/WW/view/en/46817803
\2\ Siemens I IA/DT Customer Support http://support.automation.siemens.com
\3\ Manual: TeleService S7-Library V6.1 http://support.automation.siemens.com/WW/view/en/24781774
\4\ Manual: S7-CPs for Industrial http://support.automation.siemens.com/WW/view/en/30374198
Ethernet Configuring and
Commissioning, Part A (see
chapter 8)
Copyright
8 History
Copyright
Table 8-1
Version Date Modifications
V1.0 12/13 First version for STEP 7 V12
5
Here still called Internet Message Format