SMTP -Java version of HyperTerminal version giving ERROR | Thales IoT Developer Community
July 6, 2015 - 9:34pm, 8019 views
I am able to send an SMTP with attached fileusing HyperTerminal, however when trying to do the same using Java, I get an error. I am having problems detecting where my error(s) is. The HyperTerminal version works fine and I receive a SMTP with attached file, but my JAVA version just generates ERROR – with no other information, although verbose error messages enabled.
Any help would be appreciated to help to identify where the issue is.
Gives ^cscs: GSM ucs2
SMTP : HyperTerminal
at^siss=1,"user","****\00******.co.uk" ...\00 = @ for using HyperTerminal
at^siss=1,"smFrom","****\00******.co.uk" ... \00 = @
at^siss=1,smMsg, "FFS Data File attached"
at^siss=1,path, file:///a:/Dir1/ ... path to file on FFS
at^siss=1,"cmd","files" ... ‘at’ send single file, ‘files – send up to 5 files *1
at^siss=1,"files","Event1.txt" .. attachment file in a:\Dir1 on Module (Disk A) on the EHS6T
at^siso=1 ... open internet connection
at^SISC=1 ... close Internet connection
^SIS: 1,0,4400,"Smtp open(auth.smtp.1and1.co.uk:465)"
^SIS: 1,0,4400,"SSL-Info: TLS, 3.3, TLS\11DHE\11RSA\11WITH\11AES\11256\11GCM\11S
^SIS: 1,0,4400,"SSL-Cert: C=US;O=thawte, Inc.;CN=thawte SSL CA - G2"
^SIS: 1,0,4400,"220 kundenserver.de (mreue002) Nemesis ESMTP Service ready"
^SIS: 1,0,4400,"250-kundenserver.de Hello \1b<auth.smtp.1and1.co.uk\1b> \1b<31.1
^SIS: 1,0,4400,"Auth OK"
^SIS: 1,0,4400,"Mail send OK"
^SISW: 1,2 ...data successfully sent.
Above works with SMTP + file attachment being received.
SMTP: Java - core code only shown.
String smtpCMEE = atc_Cmd.send ("at+CMEE=2\r"); … verbose error reporting.
String conType_Response = atc_Cmd.send("AT^SICS=0,conType,\"gprs0\"\r");
String user_Response = atc_Cmd.send("AT^SICS=0,user, \”user\”\r");
String passWd_Response = atc_Cmd.send("AT^SICS=0, passwd, \"\password"\r");
String apn_Response = atc_Cmd.send("AT^SICS=0, apn, \”everywhere\”\r");
String smtpSMTP_Response = at.send ("at^siss=1, \"srvType\", \"SMTP\"\r");
String smtpconID_Response = at.send ("at^siss=1, \"conID\", 0\r");
String smtpAddress = at.send ("at^siss=1, \"address\", \"smtp://auth.smtp.1and1.co.uk\"\r");
String smtpSubject_Response = at.send ("at^siss=1, \"smSubj\", subjectStr\r");
String smtpUsername_Response = at.send ("at^siss=1, \"user\", \"****@******.co.uk\"\r");
String smtpPasswd_Response = at.send ("at^siss=1, \"passwd\", \"*******\"\r");
String smtpFrom_Response = at.send ("at^siss=1, \"smFrom\", \"****@******.co.uk\"\r");
String smtpTo_Response = at.send ("at^siss=1, \"smRcpt\", \"*******@*******.com\"\r");
String smtpRcpt_Response = at.send ("at^siss=1, \"smCC\", \"******@******.com\"\r");
String smtpAuth_Response = at.send ("at^siss=1, \"smAuth\", \"login\"\r");
String smtpMsg_Response = at.send ("at^siss=1, \"smMsg\", \"FFS Data File attached\"\r");
String smtpPath_Response = at.send ("at^siss=1, \"path\", \"file:///a:/Dir1/\"\r");
String smtpCmd_Response = at.send ("at^siss=1, \"cmd\", \"files\"\r");
String smtpFiles1_Response = at.send ("at^siss=1, \"files\", \"Event1.txt\"\r");
String smtpOpen_Response = at.send ("at^siso=1\r");
ERROR .. on opening Internet session
what if you would print out responses like when you call
so that you would see if all AT commands return OK? Or do you allready do this. For some AT command wait time of 1000ms isn't enought. Don't know how is it with command that have to do with internet connection, but on AT^SJAM you sometimes have to wait even 5 seconds or more.
So check if you get that OK back and try incresaing wait time for commands which give no response, if there are such commands.
For this scenario you should also register ATCommandListener to see all the ^SIS URC's.
In that case you would probably be able to see your error message.
I have reproduced your problem and got this:
^SIS: 1,0,1000,"PARA-ERR: Address wrong"
The problem here is the same as with the terminal: that Java uses UTF8 encoding while AT interface uses GSM encoding by default. The solution here is to replace '@' character with '\00' escape as you have been doing for terminal. In Java you need to write '\\00'.
With that modification I was able to send the email.
Thank you for your response. All the commands were giving OK response, as well as the expected URC's - the same responses were given for HyperTerminal and Java (apart from the final open command) which is why I didn't include them - since the responses were the same this suggested to me that it wasn't a simple timing issue.
I hadn't appreciated that Java uses UTF8 encoding and thus would also need escape sequences for special characters - previously I had tried \00, but the program just 'hung', and thus thought I was going down the wrong track.
When I was creating FTP transfers it would provide the more verbose messages and helped to indicate where my error(s) were - but for some reason with the SMPT it just produced ERROR. What am I missing for giving the more verbose message in SMTP that were given with the FTP transfers?. I am using the same setup / configuration (CMEE etc) routines prior to calling up FTP or SMTP option.
I will try your \\00 solution tomorrow.
There is no more possibilities then for FTP. To get the more verbose error messages you set AT+CMEE=2. But you are already doing it and it's not helpful here.
More information you get as URC's. In terminal you just get them and in Java you need to register the listener to get and process them.
I hope that \\00 will solve the problem.
I tried the \\00, but unfortunately it made no obvious difference, still just getting ERROR.
A listener is implemented - though just used to generate a flag when a URC is called - processing to be added at a later date.
Just re-read the error message you received - this indicates the issue was on the address parameter which shows a typo on my part - should be smtps:// - not smtp://, to match the HyperTerminal version. I'll try again tomorrow.
I've noticed that you use smtp in java (I have used smtps for my server) but didn't notice that you have used smtps in the terminal - just assumed that you have double checked this ;) So maybe that will solve the problem.
Just print out URC's, try to open in the terminal the connection configured in Java or vice versa and you'll get it working.
Still having issues when trying to send an SMTP with an attached file.
Previously I noticed when sending an SMTP, with attached file using the above AT commands from a HyperTerminal connection:
If cmd = AT the attached file would be sent, but it was received with the correct filename but it was an empty file.
If cmd = files, the attached file would be sent and received correctly with the expected file name and contents, even though only one attached file was being sent.
Java / Netbeans 7.2
When I use the above Java code but use cmd = files via, I will get ERROR when I issue at^siso to open the Internet session.
If I use at.send ("at^siss=2, \"cmd\", \"AT\"\r") I am back to an empty file being received, but with the correct filename.
If I try and send the same file twice, at.send ("at^siss=2, \"files\", \"Event1.txt, Event1.txt\"\r"), I still get a ERROR on opening the internet session.
Not sure what is going on.
the Java API offers to convert Strings to the GSM alphabet. So there is no need to use excape sequences. Just convert the String by the class com.cinterion.io.ATStringConverter and methode
public static String Java2GSM(String str)
PS: there are also ways to use FTP and SMTP directly via socket w/o using AT commands which is much more Java like
I started out with nothing... I still have most of it.
The use of sockets may be the 'truer' Java way, but I find the use of sockets more difficult due to there being less associated documentation on what is actually occuring within the sockets. If everthing works first time - which in my case is rare! I find I end up struggling to find the information to try and work out what is going on - or not - for debugging the application - and thus more reliant on trying to find working examples. But that may be just due to my slightly greater familiarity with 'at' commands compared to 'sockets'.
How do you send the file contents with "at"? The content of the attachment should be provided using AT^SISW after the service was opened with AT^SISO.