This function will add text to the email message. An email must be created by smtpNew before text can be added.
Once the text is added, it cannot be removed again, and the only option is to cancel the email (with smtpCancel) and start over again.
Note: the email message can only contain 4095 characters of text.
Input:
Handle : INT
The handle for the email.
Message : STRING
The text message to add.
Returns: INT
The number of free characters remaining.
-1
|
- General error.
|
-2
|
- SMTP interface is not open.
|
-3
|
- Invalid parameter(s).
|
-5
|
- Invalid mail handle.
|
-6
|
- The mail is already sent.
|
-11
|
- There is no room for the text in the email.
|
Declaration:
FUNCTION smtpAddText : INT;
VAR_INPUT
Handle : INT;
Message : STRING;
END_VAR;
Example:
INCLUDE rtcu.inc
VAR
send : DINT;
timer : TON;
gps : gpsFix;
END_VAR;
FUNCTION gps_log;
VAR
fd : FILE;
str : STRING;
END_VAR;
IF fsFileExists(name := "smtptest.txt") THEN
fd := fsFileOpen(name := "smtptest.txt");
ELSE
fd := fsFileCreate(name := "smtptest.txt");
END_IF;
IF fsFileStatus(fd := fd) = 0 THEN
gps();
str := strFormat(format := "\1,", v1 := gps.mode);
IF gps.mode = 0 THEN
str := str + ",,,,,,,";
ELSE
str := str + strFormat(format := "\1.\2.\3,", v1 := gps.year, v2 := gps.month, v3 := gps.day);
str := str + strFormat(format := "\1:\2:\3,", v1 := gps.hour, v2 := gps.minute, v3 := gps.second);
IF gps.mode = 1 THEN
str := str + ",,,,,";
ELSE
str := str + strFormat(format := "\4,", v4 := gps.latitude);
str := str + strFormat(format := "\4,", v4 := gps.longitude);
str := str + strFormat(format := "\4,", v4 := gps.speed);
str := str + strFormat(format := "\4,", v4 := gps.course);
str := str + strFormat(format := "\1,", v1 := gps.height);
END_IF;
END_IF;
str := str + strFormat(format := "\1,", v1 := gps.inview);
str := str + strFormat(format := "\1$n", v1 := gps.used);
fsFileWriteString(fd := fd, str := str);
fsFileClose(fd := fd);
END_IF;
END_FUNCTION;
PROGRAM example;
VAR
md : INT;
rc : INT;
END_VAR;
gsmPower(power := ON);
gpsPower(power := ON);
netOpen(iface := 1);
fsMediaOpen(media := 0);
smtpOpen();
timer.pt := 10000;
send := clockNow() + 86400;
DebugMsg(message := "Application running");
BEGIN
timer(trig := ON);
IF timer.q THEN
gps_log();
timer(trig := OFF);
END_IF;
IF clockNow() > send THEN
md := smtpNew(Receiver := "device@tracking.com", Subject := strFormat(format := "\4 trace", v4 := boardSerialNumber()));
smtpAddText(Handle := md, Message := strFormat(format := "Device: \1$n", v1 := boardType()));
smtpAddText(Handle := md, Message := strFormat(format := "Fw: \1.\2$n", v1 := boardVersion() / 100, v2 := boardVersion() MOD 100));
smtpAddText(Handle := md, Message := strFormat(format := "App: " + verGetAppName() + "$n"));
smtpAddText(Handle := md, Message := strFormat(format := "Ver: \1.\2$n", v1 := verGetAppVersion() / 100, v2 := verGetAppVersion() MOD 100));
smtpAddAttachment(Handle := md, Filename := "smtptest.txt");
rc := smtpSendX(Handle := md);
IF rc = 0 THEN
rc := smtpAwaitCompletion(Handle := md);
IF rc = 0 THEN
fsFileDelete(name := "smtptest.txt");
DebugMsg(message := "Mail sent");
send := clockNow() + 86400;
ELSE
DebugFmt(message := "Failed to send mail! (errno=\1)", v1 := rc);
send := clockNow() + 300;
END_IF;
ELSE
DebugFmt(message := "Failed to send mail! (errno=\1)", v1 := rc);
send := clockNow() + 300;
END_IF;
END_IF;
END;
END_PROGRAM;
|