User Tools

Site Tools


sending_20an_20email_20automatically

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
sending_20an_20email_20automatically [2018/04/13 00:42]
richardrussell
sending_20an_20email_20automatically [2018/04/17 18:40] (current)
tbest3112 Added syntax highlighting
Line 7: Line 7:
 ===== Using an email client ===== ===== Using an email client =====
 \\  The advantages of this method are that it's simple, requires no configuration and can work even with mail servers requiring authentication. The disadvantage is that the process is not fully automatic: the user still has to initiate transmission by clicking on **send**. It's therefore not suitable if you want to send an email covertly or without any user intervention.\\ \\  To adopt this method use code similar to the following:​\\ \\  \\  The advantages of this method are that it's simple, requires no configuration and can work even with mail servers requiring authentication. The disadvantage is that the process is not fully automatic: the user still has to initiate transmission by clicking on **send**. It's therefore not suitable if you want to send an email covertly or without any user intervention.\\ \\  To adopt this method use code similar to the following:​\\ \\ 
 +<code bb4w>
         SYS "​ShellExecute",​ 0, 0, "​mailto:"​+to$+ \         SYS "​ShellExecute",​ 0, 0, "​mailto:"​+to$+ \
         \                         "?​subject="​+subject$+ \         \                         "?​subject="​+subject$+ \
         \                         "&​body="​+body$,​ 0, 0, 0         \                         "&​body="​+body$,​ 0, 0, 0
 +</​code>​
 Here **to$** is the email address of the main recipient, **subject$** is the subject line and **body$** is the body of the message. **to$** can optionally consist of two or more addresses separated by commas.\\ \\  If you want to **copy** the message to other recipients you can do that as follows:​\\ ​ Here **to$** is the email address of the main recipient, **subject$** is the subject line and **body$** is the body of the message. **to$** can optionally consist of two or more addresses separated by commas.\\ \\  If you want to **copy** the message to other recipients you can do that as follows:​\\ ​
 +<code bb4w>
         SYS "​ShellExecute",​ 0, 0, "​mailto:"​+to$+ \         SYS "​ShellExecute",​ 0, 0, "​mailto:"​+to$+ \
         \                         "?​cc="​+cc$+ \         \                         "?​cc="​+cc$+ \
         \                         "&​subject="​+subject$+ \         \                         "&​subject="​+subject$+ \
         \                         "&​body="​+body$,​ 0, 0, 0         \                         "&​body="​+body$,​ 0, 0, 0
 +</​code>​
 Again, **cc$** can optionally consist of two or more addresses separated by commas.\\ \\  If you prefer to **blind copy** the message (that is, the recipients don't know to whom other copies have been sent) replace **cc** with **bcc**:\\ \\  Again, **cc$** can optionally consist of two or more addresses separated by commas.\\ \\  If you prefer to **blind copy** the message (that is, the recipients don't know to whom other copies have been sent) replace **cc** with **bcc**:\\ \\ 
 +<code bb4w>
         SYS "​ShellExecute",​ 0, 0, "​mailto:"​+to$+ \         SYS "​ShellExecute",​ 0, 0, "​mailto:"​+to$+ \
         \                         "?​bcc="​+bcc$+ \         \                         "?​bcc="​+bcc$+ \
         \                         "&​subject="​+subject$+ \         \                         "&​subject="​+subject$+ \
         \                         "&​body="​+body$,​ 0, 0, 0         \                         "&​body="​+body$,​ 0, 0, 0
 +</​code>​
 If the body of the message consists of more than a single line then you must represent the line terminators in a special way. Rather than the conventional CRLF (CHR$13+CHR$10) you must use the character sequence ""​%0D%0A""​. Because **%** and **&** have special meanings, if they appear in the body of the message you must encode them as ""​%25""​ and ""​%26""​ respectively. If necessary you can do the encoding using this function:\\ \\  If the body of the message consists of more than a single line then you must represent the line terminators in a special way. Rather than the conventional CRLF (CHR$13+CHR$10) you must use the character sequence ""​%0D%0A""​. Because **%** and **&** have special meanings, if they appear in the body of the message you must encode them as ""​%25""​ and ""​%26""​ respectively. If necessary you can do the encoding using this function:\\ \\ 
 +<code bb4w>
         DEF FNmailencode(A$)         DEF FNmailencode(A$)
         LOCAL B$, I%         LOCAL B$, I%
Line 33: Line 40:
         NEXT I%         NEXT I%
         =B$         =B$
 +</​code>​
 \\  \\ 
 ===== Using BBC BASIC code ===== ===== Using BBC BASIC code =====
 \\  This approach gives you more control over the content of the email, and allows you to send it without any user interaction (assuming there is an internet connection). However there are a couple of disadvantages:​ you need to know the name (or IP address) of the SMTP server to be used, and it cannot work with a server which requires authentication. In practice this usually means you need to use **//the '​local'​ SMTP server provided by the ISP supplying the internet connection//​**. There is, as far as I know, no way of discovering this automatically.\\ \\  You can send an email using the procedure below. The **to$**, **cc$**, **bcc$**, **subject$** and **body$** parameters have the same meaning as in the previous example, except that there'​s no need to do any special encoding of the message body. The **smtp$** parameter is the name of the SMTP server (as discussed above), **from$** is the email address of the sender (which must be valid) and **replyto$** is an optional address to which replies should be addressed.\\ \\  The code uses the [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​socklib|SOCKLIB library]] so there must be an **"​INSTALL @lib$+"​SOCKLIB""​** statement previously in the program. \\  This approach gives you more control over the content of the email, and allows you to send it without any user interaction (assuming there is an internet connection). However there are a couple of disadvantages:​ you need to know the name (or IP address) of the SMTP server to be used, and it cannot work with a server which requires authentication. In practice this usually means you need to use **//the '​local'​ SMTP server provided by the ISP supplying the internet connection//​**. There is, as far as I know, no way of discovering this automatically.\\ \\  You can send an email using the procedure below. The **to$**, **cc$**, **bcc$**, **subject$** and **body$** parameters have the same meaning as in the previous example, except that there'​s no need to do any special encoding of the message body. The **smtp$** parameter is the name of the SMTP server (as discussed above), **from$** is the email address of the sender (which must be valid) and **replyto$** is an optional address to which replies should be addressed.\\ \\  The code uses the [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​socklib|SOCKLIB library]] so there must be an **"​INSTALL @lib$+"​SOCKLIB""​** statement previously in the program.
  
-<​code ​test68+<​code ​bb4w
         DEF PROCsendmail(smtp$,​from$,​to$,​cc$,​bcc$,​subject$,​replyto$,​body$)         DEF PROCsendmail(smtp$,​from$,​to$,​cc$,​bcc$,​subject$,​replyto$,​body$)
         LOCAL D%, S%, skt%, reply$         LOCAL D%, S%, skt%, reply$
sending_20an_20email_20automatically.txt ยท Last modified: 2018/04/17 18:40 by tbest3112