Beckhoff twincat SMTP supplement

Pete:-)

Member
Join Date
Nov 2008
Location
SML
Posts
4
Hi,

This is my first post on this forum and I would like to say that it very neat to see people helping each other on the plc related things.

For the moment I have a problem with Beckhoff SMTP supplement that does not want to work.

1) Program is running locally on a pc with twincat installed and running.
2) The IO device I am using to do local test is the virtual ethernet device.
3) The program itself is made in Twincat plc control.
4) Now I have a program that I have been running locally more then once. All this seems to work.

Now comes the problem. The program compiles without any error. So library,.....are all OK.
I have added the function block FB_SMTPV2 for sending emails from the plc.

"Here you have the complete code = copy from infosys"
I have replaced all the private stuff with XXXX.
When I run this program I get the error coming from the function block 1798 which is an ADS Error something to do with parameter values.

What could be the problem? Again all this is working locally on 1 pc and there is nothing connected to the pc itself.

PROGRAM EMAIL
VAR
fb_smtp1 :FB_SmtpV2 ;
bSend : BOOL;
bBusy : BOOL;
bError : BOOL;
nErrID : UDINT;
Zeit: TON;
bIn: BOOL;
msg: STRING[254];
bytemsg: ARRAY [0..511999] OF BYTE;
cbWrite: UDINT;
i: INT;
init: BOOL := FALSE;
sUsername: STRING;
sPassword: STRING;
END_VAR

Zeit(
IN:= bIn,
PT:= t#10S,
Q=> bSend,
ET=> );
IF NOT init THEN
cbWrite := MEMCPY(ADR(bytemsg), ADR(msg), LEN(msg));
i:=0;
FOR i := 0 TO 254 DO
msg :=CONCAT(msg, 'X');
END_FOR
FOR i := 0 TO 1960 DO
cbWrite := cbWrite + MEMCPY(ADR(bytemsg) + cbWrite, ADR(msg), LEN(msg)-1);
END_FOR
init := TRUE;
END_IF
fb_smtp1(
sNetId:= '192.168.2.112.1.1',
sSmtpServer:= 'Here I used the same SMTP outgoing server as configured in my outlook',
sUsername := 'XXXXXX',
sPassword := 'XXXXXX',
nAuth:=2,
sFrom:= 'From me',
sTo:= '[email protected] ,
sCc:= '' ,
sBcc:= '' ,
sSubject:= 'TcSmtp Service Test',
pMessage:= ADR(bytemsg) ,
cbMessage:= cbWrite,
bExecute:= bSend,
tTimeout:= t#20s,
bBusy=> bBusy,
bError=> bError,
nErrId=> nErrID
);
IF bBusy = TRUE THEN
bIn:= FALSE;
ELSIF bBusy = FALSE THEN
bIn:= TRUE;
END_IF
 
I have never used the SMTP server, but I will take a stab at this. According to the documentation there are two things that must occur:

1) The TwinCAT ADS SMTP service must be running on the remote ADS device (sounds like this is your local PC), so that the byte stream can be received and processed into an e-mail. Is this service running on your PC?

2) Note that password checking must be disabled on the SMTP server, since the TwinCAT ADS SMTP service does not register on the server via password checking.

Also, if the SMTP server is also running on the same PC as TwinCAT, I would set sNetId='' just to eliminate any possible AZMS Net ID typos.
 
1) The TwinCAT ADS SMTP service must be running on the remote ADS device (sounds like this is your local PC), so that the byte stream can be received and processed into an e-mail. Is this service running on your PC?

I suppose it is running. How can I check if it running? The only thing I did is installing the Twincat supplement for SMS/SMTP for xp.
I red the following "If you use the Win32 version a logfile called TcMailSrv.log will be created in the TwinCAT directory." When you open it contains stuff like this
"28/11/2008 9:01:08 - Service started
28/11/2008 9:01:38 - Service started
28/11/2008 10:03:39 - Service started
28/11/2008 10:08:43 - Service started
28/11/2008 10:14:12 - Service started
28/11/2008 11:01:59 - Service started
28/11/2008 11:08:24 - Service started
28/11/2008 11:09:41 - Service started
28/11/2008 11:28:16 - Service started
28/11/2008 11:34:33 - Service started
28/11/2008 14:57:44 - Service started
28/11/2008 15:02:06 - Service started
28/11/2008 15:28:46 - Service started
28/11/2008 15:30:21 - Service started
28/11/2008 15:30:23 - Service started
28/11/2008 15:30:36 - Service started
28/11/2008 15:30:40 - Service started
28/11/2008 17:00:00 - Service started
28/11/2008 17:04:47 - Service started
28/11/2008 17:16:49 - Service started
28/11/2008 17:16:53 - Service started
28/11/2008 17:19:28 - Service started
28/11/2008 17:22:20 - Service started
28/11/2008 17:22:23 - Service started
28/11/2008 17:26:31 - Service started
28/11/2008 17:26:48 - Service started
29/11/2008 7:41:31 - Service started
29/11/2008 10:18:12 - Service started
29/11/2008 13:52:13 - Service stopped
29/11/2008 13:53:58 - Service started
29/11/2008 18:26:30 - Service stopped
29/11/2008 18:28:11 - Service started
29/11/2008 22:02:27 - Service started
30/11/2008 0:09:32 - Service stopped
30/11/2008 20:56:41 - Service started
30/11/2008 21:29:27 - Service stopped
30/11/2008 21:29:30 - Service started"


I suppose this is the proof that the service is running.


2) Note that password checking must be disabled on the SMTP server, since the TwinCAT ADS SMTP service does not register on the server via password checking.

I am using the SMTP server of my ISP. This works with a username and a password. I have no other possibility. I am using the "FB_SmtpV2" block. This one accepts username and password if I understood it well.
This is what they write about the block "The PLC block FB_SmtpV2 allows to send mails from a smtp server that requires authentication."


Also, if the SMTP server is also running on the same PC as TwinCAT, I would set sNetId='' just to eliminate any possible AZMS Net ID typos.

I tried this but it still give the error 1798.

I have been trying to understand how the block works. You have to know that my pc that runs twincat is connected via WIFI with my router. So the block has to sent a message via the WIFI link to my router and then to my ISP. How does the service know to who to send? I am a bit lost.


 
You need to have installed Beckhoff Twincat TCP/IP server because it uses own TCP/IP socket client/server.
Also I had problems with constructing emails as every e-mail has header like "Content-Type: text/plain; charset=ISO-8859-2; format=flowed$0D$0AContent-Transfer-Encoding: 7bit$0D$0A$0D$0A%S$0D$0A"
so you will need to experiment a little with this.
 
1) The TwinCAT ADS SMTP service must be

I am using the SMTP server of my ISP. This works with a username and a password. I have no other possibility. I am using the "FB_SmtpV2" block. This one accepts username and password if I understood it well.
This is what they write about the block "The PLC block FB_SmtpV2 allows to send mails from a smtp server that requires authentication."

Sorry dont know anything about the product but if you are in any doubt about the SMTP server you can use one the PC itself, there is plenty of free ones out there, heres one for instance:

http://www.softstack.com/freesmtp.html
 
Twincat doesn't have SMTP server capabilites, it only acts like Outlook or Thunderbird(as SMTP client) it just opens TCP/IP socket connection on port 25 and sends pretty much raw data to the SMTP server(which can be on local PC or somewhere in the network, there are no restrictions, you can enter either Name or IP address of the server, ex. pop.gmail.com or 192.168.0.2). Firewall can be problem and SMTP servers which are using authentication.
I don't have V2 version of SMTP FB so I can't test authentication method, but I think it is not encrypted connection(http://en.wikipedia.org/wiki/SMTP-AUTH).

For testing purposes I would try with Free SMTP server on Local PC which Tragically1969 suggested. Add some SMTP users, start server and try to send from PLC to your Local PC IP address, of course e-mail to one of the users which you created in your free SMTP server, ex. [email protected](SMTP domain should then be mypcdomain.net).
 
Last edited:

Similar Topics

Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
738
Hello, I was wondering if anyone know how to upload a PLC program to the Beckhoff TwinCAT 3 from a file? i.e. without having the development pc...
Replies
0
Views
667
Hi anyone got any tips and tricks?? I'm at a stage wherei need to tidy up my hmi project and give all objects sensible names, I did start this...
Replies
0
Views
928
Hello, I have a System running a beckhoff IPC with twincat 2 software on it, Also i have no original source code. Is it possible with the...
Replies
1
Views
1,249
Hi all, I've inherited someone else's program and can't for the life of me figure out his use of the # symbol in one of his structured text...
Replies
5
Views
1,880
Back
Top Bottom