]> gitweb.factorcode.org Git - factor.git/blob - basis/smtp/smtp-docs.factor
scryfall: add more filter/reject words, better mtga parser
[factor.git] / basis / smtp / smtp-docs.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax io.encodings.utf8 io.sockets
4 quotations strings ;
5 IN: smtp
6
7 HELP: smtp-config
8 { $class-description "An SMTP configuration object, with the following slots:"
9     { $slots
10         { "domain" { "Name of the machine sending the email, or " { $link host-name } " if empty." } }
11         { "server" { "An " { $link <inet> } " of the SMTP server." } }
12         { "tls?" { "Secure socket after connecting to server, server must support " { $snippet "STARTTLS" } } }
13         { "read-timeout" { "Length of time after which we give up waiting for a response." } }
14         { "auth" { "Either " { $link no-auth } " or an instance of " { $link plain-auth } " or " { $link login-auth } } }
15     }
16 } ;
17
18 HELP: default-smtp-config
19 { $values { "smtp-config" smtp-config } }
20 { $description "Creates a new " { $link smtp-config } " with defaults of a one minute " { $snippet "read-timeout" } ", " { $link no-auth } " for authentication, and " { $snippet "localhost" } " port " { $snippet "25" } " as the server." } ;
21
22 { smtp-config default-smtp-config } related-words
23
24 HELP: no-auth
25 { $class-description "If the " { $snippet "auth" } " slot is set to this value, no authentication will be performed." } ;
26
27 HELP: plain-auth
28 { $class-description "If the " { $snippet "auth" } " slot is set to this value, plain authentication will be performed, with the username and password stored in the " { $slot "username" } " and " { $slot "password" } " slots of the tuple sent to the server as plain-text." }
29 { $notes "This authentication method is no longer supported by Outlook mail servers." } ;
30
31 HELP: <plain-auth>
32 { $values { "username" string } { "password" string } { "plain-auth" plain-auth } }
33 { $description "Creates a new " { $link plain-auth } " instance." } ;
34
35 HELP: login-auth
36 { $class-description "If the " { $snippet "auth" } " slot is set to this value, LOGIN authentication will be performed, with the username and password stored in the " { $slot "username" } " and " { $slot "password" } " slots of the tuple sent to the server as plain-text." } ;
37
38 HELP: <login-auth>
39 { $values { "username" string } { "password" string } { "login-auth" login-auth } }
40 { $description "Creates a new " { $link login-auth } " instance." } ;
41
42 { no-auth plain-auth login-auth } related-words
43
44 HELP: with-smtp-config
45 { $values { "quot" quotation } }
46 { $description "Connects to an SMTP server using credentials and settings stored in " { $link smtp-config } " and calls the " { $link with-smtp-connection } " combinator." }
47 { $notes "This word is used to implement " { $link send-email } " and there is probably no reason to call it directly." } ;
48
49 HELP: with-smtp-connection
50 { $values { "quot" quotation } }
51 { $description "Connects to an SMTP server using credentials and settings stored in " { $link smtp-config } " and calls the quotation." }
52 { $notes "This word is used to implement " { $link send-email } " and there is probably no reason to call it directly." } ;
53
54 HELP: email
55 { $class-description "An e-mail. E-mails have the following slots:"
56     { $slots
57         { "from" "The sender of the e-mail. An e-mail address." }
58         { "to" "The recipients of the e-mail. A sequence of e-mail addresses." }
59         { "cc" "Carbon-copy. A sequence of e-mail addresses." }
60         { "bcc" "Blind carbon-copy. A sequence of e-mail addresses." }
61         { "subject" "The subject of the e-mail. A string." }
62         { "content-type" { "The MIME type of the body. A string, default is " { $snippet "text/plain" } "." } }
63         { "encoding" { "An encoding to send the body as. Default is " { $link utf8 } "." } }
64         { "body" " The body of the e-mail. A string." }
65     }
66 "The " { $slot "from" } " and " { $slot "to" } " slots are required; the rest are optional."
67 $nl
68 "An e-mail address is a string in one of the following two formats:"
69 { $list
70     { $snippet "joe@groff.com" }
71     { $snippet "Joe Groff <joe@groff.com>" }
72 } } ;
73
74 HELP: <email>
75 { $values { "email" email } }
76 { $description "Creates an empty " { $link email } " object." } ;
77
78 HELP: send-email
79 { $values { "email" email } }
80 { $description "Sends an e-mail." }
81 { $examples
82     { $code "USING: accessors smtp ;"
83     "<email>"
84     "    \"groucho@marx.bros\" >>from"
85     "    { \"chico@marx.bros\" \"harpo@marx.bros\" } >>to"
86     "    { \"gummo@marx.bros\" } >>cc"
87     "    { \"zeppo@marx.bros\" } >>bcc"
88     "    \"Pickup line\" >>subject"
89     "    \"If I said you had a beautiful body, would you hold it against me?\" >>body"
90     "send-email"
91     ""
92     }
93 } ;
94
95 ARTICLE: "smtp-gmail" "Setting up SMTP with gmail"
96 "If you plan to send all email from the same address, then setting the config variable in the global namespace is the best option. The code example below does this approach and is meant to go in your " { $link ".factor-boot-rc" } "." $nl
97 "First, we set the login and password to a " { $link <login-auth> } " tuple with our login. Next, we set the gmail server address with an " { $link <inet> } " object. Finally, we tell the SMTP library to use a secure connection."
98 { $notes
99     "Observed on 2016-03-02: Gmail has restrictions for what they consider \"less secure apps\" (these include the factor smtp client)."
100     { $list
101         { "If the account does not use 2-step verification, Gmail requires explicitly allowing access to less secure apps. Visit " { $url "https://www.google.com/settings/security/lesssecureapps" } " to turn it on. More info: " { $url "https://support.google.com/accounts/answer/6010255?hl=en" } "." }
102         { "If the account does use 2-step verification, Gmail requires the use of application-specific passwords. Visit " { $url "https://security.google.com/settings/security/apppasswords" } " to create a password for use with Factor. More info: " { $url "https://support.google.com/accounts/answer/185833?hl=en" } "." }
103     }
104 }
105 { $examples
106 { $code
107     "USING: smtp namespaces io.sockets ;"
108     ""
109     "default-smtp-config
110     \"smtp.gmail.com\" 587 <inet> >>server
111     t >>tls?
112     \"my.gmail.address@gmail.com\" \"qwertyuiasdfghjk\" <login-auth> >>auth
113     \\ smtp-config set-global"
114 }
115 } ;
116
117
118 ARTICLE: "smtp" "SMTP client library"
119 "The " { $vocab-link "smtp" } " vocabulary sends e-mail via an SMTP server."
120 $nl
121 "This library is configured by a globally scoped config tuple:"
122 { $subsections
123     smtp-config
124     default-smtp-config
125 }
126 "The auth slot is set to an instance of one of the following:"
127 { $subsections
128     no-auth
129     plain-auth
130     login-auth
131 }
132 "Constructing an e-mail:"
133 { $subsections
134     email
135     <email>
136 }
137 "Sending an email:"
138 { $subsections send-email }
139 "More topics:"
140 { $subsections "smtp-gmail" } ;
141
142 ABOUT: "smtp"