Send e-mail from a plc

What options are there to send e-mails from a PLC? Are there solutions where the SMTP server is located directly on the PLC? Are third-party devices required?

Requirements:
CPU: 5PPC2100_BY34_002
AR: AR Embedded
AS: 4.2

The email recipient should be able to be adjusted if necessary.
Internet access to the PLC control would be possible.

I took a look at the “AsSmtp”. I’m not sure if it still makes sense to use this lib. Is there a smarter way?

Hello Mario,

We use the following through a SiteManager on many of our machines:

smtpServer := ‘10.44.10.220’;

sender		:= 'do-not-reply@br-automation.com';
receiver	        := '<<recipient email address>>';
subject		:= 'test mail';
text		:= 'this is test email';

IF sendEmail THEN
	SmtpSend_0.enable 	       := TRUE;
	SmtpSend_0.pHost		       := ADR(smtpServer);
	SmtpSend_0.pUser		       := 0;//ADR(user);
	SmtpSend_0.pPassword       := 0;//ADR(password);
	SmtpSend_0.pSender	       := ADR(sender);
	SmtpSend_0.pReceiver          := ADR(receiver);
	SmtpSend_0.pSubject	       := ADR(subject);
	SmtpSend_0.pText		       := ADR(text);
	SmtpSend_0.port		       := 25;
	
	IF SmtpSend_0.status < 60000 THEN
		SmtpSend_0.enable        := FALSE;
		sendEmail			       := FALSE;
		
	END_IF;
	
END_IF;

SmtpSend_0();

Hope this helps

1 Like

We will test it. Many Thanks

Hello Mario,

Similar to what Jon shared, we investigated some years ago how to send emails from a B&R PLC using a Gmail account.

The sample project has also a guide that explains the required configuration that should be considered if this type of functionality wants to be used (at least when using a gmail account as the email server).

Project Sample Send Email Gmail & Guide.zip (878.1 KB)

If that solution fits you, be also aware that around 2022 Google changed its security policies regarding signing in to a Gmail account using an app password (in our case that would be the PLC).

That information is not included in the guide and you will probably have to turn on the 2 step verification in that account using the steps from here.

Hopefully you will find this information usefull!

Regards,
Roger

Hi Roger,

thank you very much for the sample project. I’m currently testing it. I think it will work.

Best regards,
Mario

Hi Roger,

As I have downloaded your sample project and configured the parameters as per the guide but still I am not able to send the mail from my display 4PPC70.

I am getting the error of Server is not connected.

I would really appreciate your support for solving this error.

Thanks & Regards,
Shrenik

Hello Shrenik,

I guess you mean the status “Connection with server failed”. In that case, in the section 5.1 from the guide you can find some of the most common reasons why that could happen.

I would first double check that all the required Google account security configurations are made in a way that allow the PLC to send emails. Remember to also turn on the 2 step verification as I mentioned in my previous post.

It also happened to me while I was trying to test this functionality that the network firewall was blocking the smtp communication. Just to make sure that it is not the case, I recommend you to try again using a non corporate network.

You can also test this project in simulation. Just connect your PC to different networks and check if the result is different.

Best regards,
Roger

Dear Roger,

Thanks for your reply.

As I have turn off the firewall and I have used router with SIM card in which internet is working fine.

I am sharing you the screen shot for your reference.

As i have activated 2 step verification for my account but still the problem is same.

I hope you understand my above concern.

I would really appreciate your efforts to resolve my issue for sending the email from 4PPC70.0702-20B.

Thanks & Regards,
Shrenik

Hello again Shrenik,

I assume that you are still missing some configuration on your google account. Did you created an app password for giving access to your account from the PLC? (It is mentioned in the provided link from my initial post).

Once it is created, if you use this password in your program it will work. I have tried myself and I can assure you that it works.

If after checking that, you are still having troubles to get it to work it is for sure IT related and I am afraid that I won’t have any more suggestions for you.

Of course, you could always reach your local support contact in case of need so they can take a look with you.

I am positive that you will get it working soon enough :smiley:

Regards,
Roger

Thanks Roger for support and guidelines.

I will try to resolve the issue and let you know.

Thanks & Regards,

Shrenik

Hello,

I am am using the example, everything works fine but I do not know how to enter a newLine into email body

I tried \r\n, \n and also

Any help is appreciate.

Thank you!

Hello,

I am confused as to how this sample project was able to work? When attempting to use “smtp.gmail.com” as my pHost address, the SmtpsSend function returns error 32700 stmpERR_PARAMETER “One of the parameters pHost, pReceiver or pSender is NULL, or the IP address (pHost) specified for the server is invalid.”

According to the help docs, the supported IP address formats are numeric quartets (###.###.###.###). So I am curious as to how the project worked with “smtp.gmail.com”? I am aiming to use the same gmail smtp server, but not sure what pHost IP address to use.

Kind Regards,
Kenan

Hi Kenan,

the “pHost” input can be used for the IP address or the name of the SMTP server.

In case of using the name of the server, for name resolution DNS has to be activated inside the PLC configuration, and the DNS server must be reachable.

Best regards!

1 Like