SMTP -Java version of HyperTerminal version giving ERROR | Telit Cinterion IoT Developer Community
July 6, 2015 - 9:34pm, 8537 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.
At+cscs=?
Gives ^cscs: GSM ucs2
SMTP : HyperTerminal
at^sics=0,"conType","gprs0"
OK
at^sics=0,"user","user"
OK
at^sics=0,"passwd","passwd"
OK
at^sics=0,"apn","everywhere"
OK
at^siss=1,"srvtype","SMTP"
OK
at^siss=1,"conid",0
OK
at^siss=1,"address","smtps://auth.smtp.1and1.co.uk"
OK
at^siss=1,"smSubj","FFS Attachment"
OK
at^siss=1,"user","****\00******.co.uk" ...\00 = @ for using HyperTerminal
OK
at^siss=1,"passwd","*******"
OK
at^siss=1,"smFrom","****\00******.co.uk" ... \00 = @
OK
at^siss=1,"smRcpt","*********\00*********.com"
OK
at^siss=1,"smAuth", "login"
OK
at^siss=1,smMsg, "FFS Data File attached"
OK
at^siss=1,path, file:///a:/Dir1/ ... path to file on FFS
OK
at^siss=1,"cmd","files" ... ‘at’ send single file, ‘files – send up to 5 files *1
OK
at^siss=1,"files","Event1.txt" .. attachment file in a:\Dir1 on Module (Disk A) on the EHS6T
OK
at^siso=1 ... open internet connection
OK
^SISW: 1,1
at^SISC=1 ... close Internet connection
OK
^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
HA384"
^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
11.186.89\1b>"
^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");
Thread.sleep(1000);
String user_Response = atc_Cmd.send("AT^SICS=0,user, \”user\”\r");
Thread.sleep(1000);
String passWd_Response = atc_Cmd.send("AT^SICS=0, passwd, \"\password"\r");
Thread.sleep(1000);
String apn_Response = atc_Cmd.send("AT^SICS=0, apn, \”everywhere\”\r");
Thread.sleep(1000);
String smtpSMTP_Response = at.send ("at^siss=1, \"srvType\", \"SMTP\"\r");
Thread.sleep(1000);
String smtpconID_Response = at.send ("at^siss=1, \"conID\", 0\r");
Thread.sleep(1000);
String smtpAddress = at.send ("at^siss=1, \"address\", \"smtp://auth.smtp.1and1.co.uk\"\r");
Thread.sleep(1000);
String smtpSubject_Response = at.send ("at^siss=1, \"smSubj\", subjectStr\r");
Thread.sleep(1000);
String smtpUsername_Response = at.send ("at^siss=1, \"user\", \"****@******.co.uk\"\r");
Thread.sleep(1000);
String smtpPasswd_Response = at.send ("at^siss=1, \"passwd\", \"*******\"\r");
Thread.sleep(1000);
String smtpFrom_Response = at.send ("at^siss=1, \"smFrom\", \"****@******.co.uk\"\r");
Thread.sleep(1000);
String smtpTo_Response = at.send ("at^siss=1, \"smRcpt\", \"*******@*******.com\"\r");
Thread.sleep(1000);
String smtpRcpt_Response = at.send ("at^siss=1, \"smCC\", \"******@******.com\"\r");
Thread.sleep(1000);
String smtpAuth_Response = at.send ("at^siss=1, \"smAuth\", \"login\"\r");
Thread.sleep(1000);
String smtpMsg_Response = at.send ("at^siss=1, \"smMsg\", \"FFS Data File attached\"\r");
Thread.sleep(1000);
String smtpPath_Response = at.send ("at^siss=1, \"path\", \"file:///a:/Dir1/\"\r");
Thread.sleep(1000);
String smtpCmd_Response = at.send ("at^siss=1, \"cmd\", \"files\"\r");
Thread.sleep(1000);
String smtpFiles1_Response = at.send ("at^siss=1, \"files\", \"Event1.txt\"\r");
Thread.sleep(1000);
String smtpOpen_Response = at.send ("at^siso=1\r");
Thread.sleep(1000);
ERROR .. on opening Internet session
The attached file, Event1.txt, is a file created in FFS on the EHS6T. Thus using 'files' and 'path' to indicate the name and where the file is located on the EHS6T 'A' drive.
I am trying to use the same AT commands, used via HyperTerminal, embedded within Java. As indicated above the AT commands via HyperTerminal works fine, but not the Java version.
My version is based on the example given in 10.15.18 in the EHS6 AT Command Set V02.000A - SMTP Sending Mail with attachment from FFS.
I have not used the AT^SISW followed by data for SMTP transfers - although I use this technique for FTP transfers which appears to work fine.
I was hoping to understand why the 'at' commands via HyperTerminal can pick up a file in FFS and transfer its contents ok, but not when I embed the 'st' commands within Java.
Hello,
By sending with "at" I meant sending with "at" parameter instead of "files" where you have written that the empty file is received. And in that case the content of the attachment should be provided using AT^SISW command.
Have you registered a listener for URC's in your Java application? What is the current output?
This should be working from terminal and Java. So maybe there's still some difference in the commands you issue.
Please add also reading of configured parameters in Java before establishing the connection.
Regards,
Bartłomiej
Thank you for your reply.
I have registered a listener, but whereas I get URC responses for any FTP transfers I do not seem to be getting any for the SMTP transfers, even though the initialisation code is the same, with a flag to eithe send a SMTP or a FTP transfer. I will add code to read configured parameters prior to opening the SMTP session to see if this gives more information.
All I can think of is are there any other escape sequences needed for the Java code, since this is the only difference between the code used via HyperTerminal and that used via java.
Hello,
You should get URC's like you get without Java. Please make sure that you have added the listener to the same ATCommand instance that is used for SMTP.
And you can try to configure the service via terminal and then try to run it via Java or the opposite configure via Java and run via terminal. Or just print and compare the both configurations. There must be something.
Regards,
Bartłomiej
Thank you for your reply.
The Listener is implemented, the reason for no URC's, is because I was not using at^sisw with cmd=AT, and thus not initiating the URC's. If I add data via at^sisw then the URC's are called.
Using at^sisi=? indicated where my typo was, now sending attached file with contents at long last.
Although receiving contents, noticed that with FTP transfers I have no issues when using multiple at^sisw to send larger blocks of data and they are correctly appended to the file created on the FTP Server.
However sending the same data via SMTP only the 1st 1000 bytes of the created file is correctly received, the rest are unprintable characters, square with a ? inserted. Tried linefeeds but made no difference. Is there any way around this? - want to avoid sending multiple files and then recombining them after received. Can't use FFS for the files since they are restricted to < 1000 bytes.
Another issue I get is that any message in the main body of the email missed out any inserted spaces. Tried '_' without quotes to add the space, but just gives a diamond symbol with ? inside. Can't see anything obvious in the GSM character set that would cause this.
Any thoughts ??
Hello,
Could you please provide ATI1 output of your module.
I've made a test on my module with 172 kB jpg file and there are no problems.
I can also see spaces in my message. I use the default "GSM" encoding on my module and my code is based on yours.
Regards,
Bartłomiej
Output :
Set CMEE=2
Create Internet Connection Profile.
Registration Response: AT+CREG?
Poll ASC0 for data and wait for response
Chars received: 1182
Create a SMTP Connection
SMTP: Connection Service Type SMTP Set: at^siss=2, "srvType", "SMTP"
OK
SMTP: Connection ID Set: at^siss=2, "conID", 0
OK
SMTP: Connection SMTP Server Address Set: at^siss=2, "address", "smtps://auth.smtp.1and1.co.uk"
OK
SMTP: Connection Subject Heading Set: at^siss=2, "smSubj", "SMTP File Attachment"
OK
SMTP: Connection user Address: at^siss=2, "user", "****\00*******"
OK
SMTP: Connection Password Set: at^siss=2, "passwd", "*******"
OK
SMTP: Connection SMTP 'from' Set: at^siss=2, "smFrom", "****\00*********"
OK
SMTP: Connection SMTP 'to' Set: at^siss=2, "smRcpt", "*****\00******"
OK
SMTP: Connection Authorisation Set: at^siss=2, "smAuth", "login"
OK
SMTP: Connection Authorisation Set: at^siss=2, "smMsg",”SMTP File 1:_See_attached.”
OK
SMTP: Path Set: at^siss=2, "path", "file:///a:/data/"
OK
SMTP: Cmd=AT Parameter Set: at^siss=2, "cmd", "AT"
OK
SMTP: Attached File Name Parameter Set: at^siss=2, "files",SMTP-Attached-File.txt
OK
SMTP: at^siss? Cmd Sent: at^siss?
^SISS: 0,"srvType",""
^SISS: 1,"srvType",""
^SISS: 2,"srvType","Smtp"
^SISS: 2,"conId","0"
^SISS: 2,"address","smtps://auth.smtp.1and1.co.uk"
^SISS: 2,"tcpMR","10"
^SISS: 2,"tcpOT","6000"
^SISS: 2,"user","****\00********"
^SISS: 2,"passwd","*****"
^SISS: 2,"path","file:///a:/data/"
^SISS: 2,"files","SMTP-Attached-File.txt"
^SISS: 2,"cmd","AT"
^SISS: 2,"smFrom","****\00********"
^SISS: 2,"smRcpt","********\00*****"
^SISS: 2,"smSubj","SMTP File Attachment"
^SISS: 2,"smMsg","SMTP File 1:_See_Attached.\00\00."
^SISS: 2,"smAuth","login"
^SISS: 3,"srvType",""
^SISS: 4,"srvType",""
^SISS: 5,"srvType",""
^SISS: 6,"srvType",""
^SISS: 7,"srvType",""
^SISS: 8,"srvType",""
^SISS: 9,"srvType",""
OK
RING Changed true
URC - ATEvent
^SISW: 2,1
RING Changed false
SMTP: Open SMTP Session Sent: at^siso=2 ... Open SMTP session
OK
SISW: 1,1 detected, ready to accept data
StrLength5_1 = 734 ... Length of string to send
... Displaying the 734 bytes show the ASCII data as expected
Write SMTP Str Request: AT^SISW=2, 734,0 ... Request to send 734 bytes.
^SISW: 2,734,0 ... Request ack.
RING Changed true
URC - ATEvent
^SISW: 2,1 ... Ready for new data
RING Changed false
StrLength5_2 = 462 ... Length of 2nd string to send
... Displaying the 462 bytes show the ASCII data as expected
Write SMTP Str Request: AT^SISW=2, 462,0, ... Request to send 462 bytes.
^SISW: 2,462,0 ... Request ack.
RING Changed true
URC - ATEvent
^SISW: 2,1 ... Ready for new data
RING Changed false
RING Changed true
URC - ATEvent
^SIS: 2,0,4400,"Smtp open(auth.smtp.1and1.co.uk:465)"
^SISS detected.
RING Changed false
EOD, End of Data sent: AT^SISW=2, 0, 1 ... EOD
^SISW: 2,0,0
RING Changed true
URC - ATEvent
^SIS: 2,0,4400,"SSL-Info: TLS, 3.3, TLS\11DHE\11RSA\11WITH\11AES\11256\11GCM\11SHA384"
^SISS detected.
URC - ATEvent
^SIS: 2,0,4400,"SSL-Cert: C=US;O=thawte, Inc.;CN=thawte SSL CA - G2"
^SISS detected.
RING Changed false
RING Changed true
RING Changed false
URC - ATEvent
^SIS: 2,0,4400,"220 kundenserver.de (mreue005) Nemesis ESMTP Service ready"
^SISS detected.
RING Changed true
URC - ATEvent
^SIS: 2,0,4400,"250-kundenserver.de Hello \1b<auth.smtp.1and1.co.uk\1b> \1b<31.111.64.133\1b>"
^SISS detected.
URC - ATEvent
^SIS: 2,0,4400,"Auth OK"
^SISS detected.
RING Changed false
RING Changed true
URC - ATEvent
^SIS: 2,0,4400,"Mail send OK"
^SISS detected.
URC - ATEvent
^SISW: 2,2 ... Indicates data transfer successful
^SISS detected.
^SISW detected.
RING Changed false
SMTP Service State, SISI:AT^SISI=2
^SISI: 2,6,0,1196,0,0 ... Current session state ‘down’
OK
SMTP Close Response: at^sisc=2 ... Close SMTP session
OK
SMTP: Connection Service Type SMTP None Set: at^siss=2, "srvType", "None"
OK
Email session closed.
Although the correct number of characters are received in the attached file, only the 1st 1000 bytes are ASCII readable. The last section of the 2nd string are just ‘0’, displaying fine until character 1000, but characters after this are unreadable – a open upright rectangle character if attached file opened in Notepad (ansii).
If copied to word then other characters displayed depending on Font style selected.
In addition smMsg:
sent as: SMTP File 1:._See_attached.;
Received as: SMTPFile1:�See�attached.@@.
Spaces missed, ‘_’ as unknown. Additional characters add at end.
Note: the same 'strings' added to a FTP file attachment are received with all characters intact.
Hello,
It seems that we've misunderstood each other a little bit. I've been sending my 172 kB jpg file from the file system.
It is possible to store and send from FFS the files that are bigger than 1000 bytes.
I've also checked sending with SISW command and unfortunately I've also found your problem. It seems that in such case only small files up to 1000 bytes can be sent. But still there is a workaround - sending files that have been previously stored in file system.
Your second problem is connected with differences between GSM and other character sets based on ASCII.
The strings passed as arguments to AT commands should be in GSM encoding.
There is a certain amount of characters that are coded in a different way. In case of '_' escape \11 should be used. But there shouldn't be any problems with space.
There is a chapter in the AT commands specification that covers this.
Best regards,
Bartłomiej
Thank you for your reply. At least it confirms the 1000 byte limitation for a SMTP attachment when using at^sisw which I found.
I don't understand why its not recognising the spaces since they comply with the GSM encoding - though can get around it by using the \11 escape sequence for '_' to create the spaces.