-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathexamples.go
More file actions
475 lines (393 loc) · 15.4 KB
/
examples.go
File metadata and controls
475 lines (393 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
// DO NOT MODIFY - Automatically generated from ./files/examples.txt
package main
import "fmt"
const (
examples = `
Examples
Each example mailsend-go command is a single line. In Unix back slash
can be used to continue in the next line. Also in Unix, use single
quotes instead of double quotes, otherwise if input has any shell
character like $ etc, it will get expanded by the shell. The directory
test/ has some test scripts.
Show SMTP server information
StartTLS will be used if server supports it
mailsend-go -info -smtp smtp.gmail.com -port 587
[S] 220 smtp.gmail.com ESMTP k185-v6sm17739711qkd.27 - gsmtp
[C] HELO localhost
[C] EHLO localhost
[S] 250-smtp.gmail.com at your service, [x.x.x.x]
[S] 250-SIZE 35882577
[S] 250-8BITMIME
[S] 250-STARTTLS
[S] 250-ENHANCEDSTATUSCODES
[S] 250-PIPELINING
[S] 250-CHUNKING
[S] 250-SMTPUTF8
[C] STARTTLS
[S] 220-2.0.0 Ready to start TLS
[C] EHLO localhost
[S] 250-smtp.gmail.com at your service, [x.x.x.x]
[S] 250-SIZE 35882577
[S] 250-8BITMIME
[S] 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
[S] 250-ENHANCEDSTATUSCODES
[S] 250-PIPELINING
[S] 250-CHUNKING
[S] 250-SMTPUTF8
Certificate of smtp.gmail.com:
Version: 3 (0x3)
Serial Number: 149685795415515161014990164765 (0x1e3a9301cfc7206383f9a531d)
Signature Algorithm: SHA256-RSA
Subject: CN=Google Internet Authority G3,O=Google Trust Services,C=US
Issuer: GlobalSign
Not before: 2017-06-15 00:00:42 +0000 UTC
Not after: 2021-12-15 00:00:42 +0000 UTC
[C] QUIT
[S] 221-2.0.0 closing connection k185-v6sm17739711qkd.27 - gsmtp
Use SSL. Note the port is different
mailsend-go -info -smtp smtp.gmail.com -port 465 -ssl
Print SMTP server certificate chain
mailsend-go -info -smtp smtp.gmail.com -port 587 -printCerts
[S] 220 smtp.gmail.com ESMTP 6a1803df08f44-80166e2f32bsm34741116d6.41 - gsmtp
[C] HELO localhost
[C] EHLO localhost
[S] 250-smtp.gmail.com at your service, [x.x.x.x]
[S] 250-SIZE 35882577
[S] 250-8BITMIME
[S] 250-STARTTLS
[S] 250-ENHANCEDSTATUSCODES
[S] 250-PIPELINING
[S] 250-CHUNKING
[S] 250-SMTPUTF8
[C] STARTTLS
[S] 220-2.0.0 Ready to start TLS
[C] EHLO localhost
[S] 250-smtp.gmail.com at your service, [x.x.x.x]
[S] 250-SIZE 35882577
[S] 250-8BITMIME
[S] 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
[S] 250-ENHANCEDSTATUSCODES
[S] 250-PIPELINING
[S] 250-CHUNKING
[S] 250-SMTPUTF8
[C] QUIT
[S] 221-2.0.0 closing connection 6a1803df08f44-80166e2f32bsm34741116d6.41 - gsmtp
=== TLS Connection Information ===
TLS Version: TLS 1.3
Cipher Suite: 0x1301
Server Name: smtp.gmail.com
Negotiated Protocol:
Certificate Chain (3 certificates):
--- Certificate 1 ---
Subject: CN=smtp.gmail.com
Issuer: CN=WR2,O=Google Trust Services,C=US
Serial Number: 14461562026188826353951632455228095006
Not Before: 2025-09-08T08:36:45Z
Not After: 2025-12-01T08:36:44Z
Is CA: false
DNS Names: smtp.gmail.com
Key Usage: Digital Signature
Status: Valid
--- Certificate 2 ---
Subject: CN=WR2,O=Google Trust Services,C=US
Issuer: CN=GTS Root R1,O=Google Trust Services LLC,C=US
Serial Number: 170058220837755766831192027518741805976
Not Before: 2023-12-13T09:00:00Z
Not After: 2029-02-20T14:00:00Z
Is CA: true
Key Usage: Digital Signature, Certificate Sign, CRL Sign
Status: Valid
--- Certificate 3 ---
Subject: CN=GTS Root R1,O=Google Trust Services LLC,C=US
Issuer: CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE
Serial Number: 159159747900478145820483398898491642637
Not Before: 2020-06-19T00:00:42Z
Not After: 2028-01-28T00:00:42Z
Is CA: true
Key Usage: Digital Signature, Certificate Sign, CRL Sign
Status: Valid
--- Certificate Fingerprints (Leaf) ---
SHA-1: 28:88:45:90:10:20:88:BA:87:2E:0E:7C:3A:12:D6:35:EC:26:AE:90
SHA-256: 6F:F8:E2:F5:D4:AE:5A:FF:92:4A:5F:AC:88:80:14:3A:30:33:7A:CF:EE:33:94:82:EF:2A:93:47:80:E4:18:EF
=====================================
mailsend-go -info -smtp smtp.gmail.com -port 465 -ssl -printCerts
[S] 220 smtp.gmail.com ESMTP 6a1803df08f44-80166781d27sm35134546d6.45 - gsmtp
[C] HELO localhost
[C] EHLO localhost
[S] 250-smtp.gmail.com at your service, [x.x.x.x]
[S] 250-SIZE 35882577
[S] 250-8BITMIME
[S] 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
[S] 250-ENHANCEDSTATUSCODES
[S] 250-PIPELINING
[S] 250-CHUNKING
[S] 250-SMTPUTF8
[C] QUIT
[S] 221-2.0.0 closing connection 6a1803df08f44-80166781d27sm35134546d6.45 - gsmtp
=== TLS Connection Information ===
TLS Version: TLS 1.3
Cipher Suite: 0x1301
Server Name: smtp.gmail.com
Negotiated Protocol:
Certificate Chain (3 certificates):
--- Certificate 1 ---
Subject: CN=smtp.gmail.com
Issuer: CN=WR2,O=Google Trust Services,C=US
Serial Number: 14461562026188826353951632455228095006
Not Before: 2025-09-08T08:36:45Z
Not After: 2025-12-01T08:36:44Z
Is CA: false
DNS Names: smtp.gmail.com
Key Usage: Digital Signature
Status: Valid
--- Certificate 2 ---
Subject: CN=WR2,O=Google Trust Services,C=US
Issuer: CN=GTS Root R1,O=Google Trust Services LLC,C=US
Serial Number: 170058220837755766831192027518741805976
Not Before: 2023-12-13T09:00:00Z
Not After: 2029-02-20T14:00:00Z
Is CA: true
Key Usage: Digital Signature, Certificate Sign, CRL Sign
Status: Valid
--- Certificate 3 ---
Subject: CN=GTS Root R1,O=Google Trust Services LLC,C=US
Issuer: CN=GlobalSign Root CA,OU=Root CA,O=GlobalSign nv-sa,C=BE
Serial Number: 159159747900478145820483398898491642637
Not Before: 2020-06-19T00:00:42Z
Not After: 2028-01-28T00:00:42Z
Is CA: true
Key Usage: Digital Signature, Certificate Sign, CRL Sign
Status: Valid
--- Certificate Fingerprints (Leaf) ---
SHA-256: 6F:F8:E2:F5:D4:AE:5A:FF:92:4A:5F:AC:88:80:14:3A:30:33:7A:CF:EE:33:94:82:EF:2A:93:47:80:E4:18:EF
SHA-1: 28:88:45:90:10:20:88:BA:87:2E:0E:7C:3A:12:D6:35:EC:26:AE:90
=====================================
mailsend-go -info -smtp smtp-mail.outlook.com -port 587 -printCerts
[S] 220 MN2PR01CA0065.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sat, 27 Sep 2025 00:29:10 +0000 [08DDFAA3FED0C1E0]
[C] HELO localhost
[C] EHLO localhost
[S] 250-MN2PR01CA0065.outlook.office365.com Hello [x.x.x.x]
[S] 250-SIZE 157286400
[S] 250-PIPELINING
[S] 250-DSN
[S] 250-ENHANCEDSTATUSCODES
[S] 250-STARTTLS
[S] 250-8BITMIME
[S] 250-BINARYMIME
[S] 250-CHUNKING
[S] 250-SMTPUTF8
[C] STARTTLS
[S] 220-2.0.0 SMTP server ready
[C] EHLO localhost
[S] 250-MN2PR01CA0065.outlook.office365.com Hello [x.x.x.x]
[S] 250-SIZE 157286400
[S] 250-PIPELINING
[S] 250-DSN
[S] 250-ENHANCEDSTATUSCODES
[S] 250-AUTH LOGIN XOAUTH2
[S] 250-8BITMIME
[S] 250-BINARYMIME
[S] 250-CHUNKING
[S] 250-SMTPUTF8
[C] QUIT
[S] 221-2.0.0 Service closing transmission channel
=== TLS Connection Information ===
TLS Version: TLS 1.3
Cipher Suite: 0x1302
Server Name: smtp-mail.outlook.com
Negotiated Protocol:
Certificate Chain (2 certificates):
--- Certificate 1 ---
Subject: CN=outlook.com,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US
Issuer: CN=DigiCert Cloud Services CA-1,O=DigiCert Inc,C=US
Serial Number: 10535063011692331098818316272276424549
Not Before: 2025-03-29T00:00:00Z
Not After: 2026-03-28T23:59:59Z
Is CA: false
DNS Names: *.clo.footprintdns.com, *.hotmail.com, *.internal.outlook.com, *.live.com, *.nrb.footprintdns.com, *.office.com, *.office365.com, *.outlook.com, *.outlook.office365.com, attachment.outlook.live.net, attachment.outlook.office.net, attachment.outlook.officeppe.net, attachments.office.net, attachments-sdf.office.net, ccs.login.microsoftonline.com, ccs-sdf.login.microsoftonline.com, hotmail.com, mail.services.live.com, office365.com, outlook.com, outlook.office.com, substrate.office.com, substrate-sdf.office.com
Key Usage: Digital Signature, Key Encipherment
Status: Valid
--- Certificate 2 ---
Subject: CN=DigiCert Cloud Services CA-1,O=DigiCert Inc,C=US
Issuer: CN=DigiCert Global Root CA,OU=www.digicert.com,O=DigiCert Inc,C=US
Serial Number: 20058375873168194746987232153701302504
Not Before: 2020-09-25T00:00:00Z
Not After: 2030-09-24T23:59:59Z
Is CA: true
Key Usage: Digital Signature, Certificate Sign, CRL Sign
Status: Valid
--- Certificate Fingerprints (Leaf) ---
SHA-1: A6:F7:EC:FB:2B:F6:31:B3:A8:4F:EB:B0:9F:FD:BB:4E:3B:0F:42:11
SHA-256: 4F:94:1A:8E:50:52:5E:09:24:4F:8F:FE:75:65:E1:6A:51:DD:10:47:04:74:94:6A:0F:BA:84:6A:86:E4:DE:8C
=====================================
Use default settings for well known mail providers
Don’t worry about the settings of -smtp, -port and -ssl for well known
mail providers. This works for gmail, yahoo, outlook, gmx, zoho and aol.
mailsend-go -info -use gmail
Send mail with a text message
Notice “auth” is a command and it takes -user and -pass arguments.
“body” is also a command and here it took -msg as an argument. The
command “body” can not repeat, if specified more than once, the last one
will be used.
mailsend-go -sub "Test" -smtp smtp.gmail.com -port 587 \
auth \
-user jsnow@gmail.com -pass "secret" \
-from "jsnow@gmail.com" -to "mjane@example.com" \
body \
-msg "hello, world!\nThis is a message"
The embedded new line \n will be converted to a real newline and the
final message will show up as two lines.
The environment variable “SMTP_USER_PASS” can be used instead of the
flag -pass.
Send mail with a HTML message
mailsend-go -sub "Test" \
-smtp smtp.gmail.com -port 587 \
auth \
-user jsnow@gmail.com -pass "secret" \
-from "jsnow@gmail.com" \
-to "mjane@example.com" -from "jsnow@gmail.com" \
body \
-msg "<b>hello, world!</b>"
The environment variable “SMTP_OAUTH_TOKEN” can be used instead of the
flag -token.
Send mail with a HTML message, use XOAUTH2
export SMTP_OAUTH_TOKEN='your_access_token'
mailsend-go -sub "Test" \
-smtp smtp.gmail.com -port 587 \
auth \
-user jsnow@gmail.com \
-oauth2 \
-from "jsnow@gmail.com" \
-to "mjane@example.com" -from "jsnow@gmail.com" \
body \
-msg "<b>hello, world!</b>"
Attach a PDF file
MIME type will be detected. Content-Disposition will be set to
“attachment”, Content-Transfer-Encoding will be “Base64”. Notice,
“attach” is a command it took -file as an arg. The command “attach” can
repeat.
mailsend-go -sub "Test" \
-smtp smtp.gmail.com -port 587 \
auth \
-user jsnow@gmail.com -pass "secret" \
-from "jsnow@gmail.com" \
-to "mjane@example.com" -from "jsnow@gmail.com" \
body \
-msg "A PDF file is attached" \
attach \
-file "/path/file.pdf"
The name of the attachment will be file.pdf. To change the attachmetn
name, use the -name flag. e.g.
attach -file "/path/file.pdf" -name "report.pdf"
Attach a PDF file and an image
Notice, the “attach” command is repeated here.
mailsend-go -sub "Test" \
-smtp smtp.gmail.com -port 587 \
auth \
-user jsnow@gmail.com -pass "secret" \
-from "jsnow@gmail.com" \
-to "mjane@example.com" -from "jsnow@gmail.com" \
body \
-msg "A PDF file and a PNG file is attached" \
attach \
-file "/path/file.pdf" \
attach \
-file "/path/file.png"
Attach a PDF file and embed an image
Content-Disposition for the image will be set to “inline”. It’s an hint
to the mail reader to display the image on the page. Note: it is just a
hint, it is up to the mail reader to respect it or ignore it.
mailsend-go -sub "Test" \
-smtp smtp.gmail.com -port 587 \
auth \
-user jsnow@gmail.com -pass "secret" \
-from "jsnow@gmail.com" \
-to "mjane@example.com" -from "jsnow@gmail.com" \
body \
-msg "A PDF file is attached, image should be displayed inline" \
attach \
-file "/path/file.pdf" \
attach \
-file "/path/file.png" \
-inline
Set Carbon Copy and Blind Carbon copy
mailsend-go -sub "Testing -cc and -bcc" \
-smtp smtp.gmail.com -port 587 \
auth \
-user example@gmail.com -pass "secret" \
-to jsoe@example.com \
-f "example@gmail.com" \
-cc "user1@example.com,user2@example.com" \
-bcc "foo@example.com" \
body -msg "Testing Carbon Copy and Blind Carbon copy"
Cc addresses will be visible to the recipients but Bcc address will not
be.
Send mail to a list of users
Create a file with list of users. The syntax is Name,email_address in a
line. Name can be empty but comma must be specified. Example of a list
file:
# This is a comment.
# The syntax is Name,email address in a line. Name can be empty but comma
# must be specified
John Snow,jsnow@example.com
Mary Jane,mjane@example.com
,foobar@example.com
Specify the list file with -list flag.
mailsend-go -sub "Test sending mail to a list of users" \
-smtp smtp.gmail.com -port 587 \
auth \
-user example@gmail.com -pass "secret" \
-f "me@example.com" \
-to "xyz@example.com" \
body \
-msg "This is a test of sendmail mail to a list of users" \
attach \
-file "cat.jpg" \
attach \
-file "flower.jpg" \
-inline \
-list "list.txt"
Add Custom Headers
Use the command “header” to add custom headers. The command “header” can
be repeated.
mailsend-go -sub "Testing custom headers" \
-smtp smtp.gmail.com -port 587 \
auth \
-user example@gmail.com -pass "secret" \
-to jdoe@example.com \
-f "example@gmail.com" \
body -msg "Testing adding Custom headers"
header \
-name "X-MyHeader-1" -value "Value of X-MyHeader-1" \
header \
-name "X-MyHeader-2" -value "Value of X-MyHeader-2"
Write logs to a file
Use the flag -log path_of_log_file.txt
mailsend-go -sub "test log" \
-smtp smtp.example.com -port 587 \
auth \
-user example@gmail.com -pass "secret" \
-to jdoe@example.com \
-f "example@gmail.com" \
body -msg "Testing log file" \
-log "/tmp/mailsend-go.log"
Specify a different character set
The default character set is utf-8
mailsend-go -sub "test character set" \
-smtp smtp.example.com -port 587 \
auth \
-user example@gmail.com -pass "secret" \
-to jdoe@example.com \
-from "example@gmail.com" \
-subject "Testing Big5 Charset" \
-cs "Big5" \
body -msg "中文測試"
------------------------------------------------------------------------
(Generated from docs/examples.md)
------------------------------------------------------------------------
`
)
// Print Examples ...
func PrintExamples() {
fmt.Println(examples)
}