SMTP data file attachment | Telit Cinterion IoT Developer Community
March 15, 2015 - 7:35pm, 5225 views
I am looking for advice on how to create a data file attachment, *txt, for sending an attachment via SMTP using AT commands.
The only examples I have found are for picking up files stored on the FFS, Flash File System. Thus I would need to create the attachment file name, *.txt, add data to it, and then send it as an attachment.
I prefer to use SMTP rather than FTP to achieve this since it makes it easier, for me anyway, for dealing with the data when it has been received.
Any help will be appreciated.
Hi,
if I understood corectly. You need code for creating txt. file and saving data into it. I think that there is somwhere an example. But here is my example based on that:
public void writeToFile(String content, String file) throws IOException //pisanja v datoteko
{
String filename_new = "file:///a:/" + file + ".txt" ; // file path
FileConnection fc;
System.out.println("opening FileConnection...");
fc = (FileConnection) Connector.open(filename_new, Connector.READ_WRITE);
if (fc.exists()) //you can change this if you don't want to delete the file before you write to it
{
fc.delete();
fc.close();
}
fc = (FileConnection) Connector.open(filename_new, Connector.READ_WRITE);
fc.create();
OutputStream os = fc.openOutputStream(fc.fileSize());
for (int i = 0; i < content.length(); i++) //we write char by char
{
os.write(content.charAt(i));
}
System.out.println("closing fc... ");
os.close();
fc.close();
}
If you also have problems with sending mail, there should also be an example from Gemalto.
Best regards,
Jure
This is what I want to achieve, but trying to do the equivalent using AT commands.
Which module do you have? Because I am not sure if you can create and write to file, using AT commands.
Regards
Jure
Hello,
In case of EHS6 module for example you can use AT^SFSA command for creating and writing to the file.
Small example:
at^sfsa="open","a:/aaa.txt",9 // create the file and open for writing
^SFSA: 0,0
OK
at^sfsa="write",0,10 // writing 10 bytes
CONNECT
// send data to file
^SFSA: 0
OK
at^sfsa="close",0 // close the file
^SFSA: 0
OK
Please check the AT commands specification for more details.
Regards,
Bartłomiej
Thank you, this seems to do what I require, though it uses the flash file system, rather than an option for using RAM since I only need temporary storage. It appears to be limited to creating a 1500 byte file sizes, so may need to create in some cases multiple text files and combine at the receiving end. Hopefully the Flash is not too slow.
Hello,
You can send up to 5 files in case of EHS6.
Please also check other possibility.
Using "cmd" parameter value "at" (AT^SISS=9,cmd,"at") you can send a single attachment to the server. The content of the attachment should be provided using AT^SISW after the service was opened with AT^SISO.
Regards,
Bartłomiej
Thankyou, I'll research that further.
Hi Bartłomiej,
I'm working on email attachment with EHS6 too, facing problems with AT^SISW transfer: when attached file's size is greater than 1000 characters, it gets truncated on reception, even if AT^SISW on exceeding bytes got affirmative answer ("^SISW:x,1").
So what is the limit to attachment's size, when trasferring it by AT^SISW?
Thanks in advance,
Federico
Hello,
It seems that this is not stated in the documentation.
If you are sure that is not your smtp server limitation maybe you have just found the limit. I have no possibility to test it this week.
Best regards,
Bartłomiej