Skip to content
Karl Dahlke edited this page Apr 29, 2024 · 29 revisions

Edbrowse as a sendmail client

Edbrowse can send email by smtp, or secure smtps. Most mail servers now require secure connections for incoming and outgoing mail, so you probably want the word secure in your mail descriptors. If you have read the chapter on fetching your email by imap or pop3, then you've seen these sample mail blocks before. Here they are again for review. If these are at the top of your .ebrc config file, you can use either one to send email. They fetch email in different ways, imap or pop3, but they both send email the same way.

#  google mail pop3
mail {
default
inserver = pop.gmail.com
outserver = smtp.gmail.com
secure
login = fflintstone
password = Pebbles276
reply = fflintstone@gmail.com
from = Fred Flintstone
}

#  google mail imap
mail {
imap
inserver = imap.gmail.com
outserver = smtp.gmail.com
secure
login = fflintstone@gmail.com
password = Pebbles276
from = Fred Flintstone
reply = fflintstone@gmail.com
}

You can send email from the command line, or from within an edbrowse session. I usually send mail interactively, however, a script would probably send mail via command line arguments. Let's explore that first.

Suppose fred and barney are in your address book, thus you can use their names as shorthand. Naturally you could use their email addresses instead. In this example, hollyrock-notice is a file containing the email you want to send.

edbrowse -m1 fred ^barney hollyrock-notice +hollyrock-brochure.pdf

-m1 means send mail through account 1. fred and barney are the recipients. In this example they must be in your address book, perhaps like this.

fred : fred.flintstone@cartoonland.com>Fred W. Flintstone : 226 Cobblestone Way, Bedrock : 67-345
fredwork : fwflintstone@SlateConstruction.com>Mr. Flintstone
barney : barney.rubble@cartoonland.com

Note: there is some controversy surrounding Fred's middle initial.

The ^ in front of barney, on the edbrowse sendmail command line, means he is a CC recipient. Use ?barney for BCC. Since Fred's name is specified in the addressbook, indicated by a greater than sign, his name will also be included as the recipient. The email, contained in the file hollyrock-notice, will be mailed to fred and barney. The first line of the file has to be a subject line, e.g. subject: How to win a Trip to Hollyrock!

Files with a leading + are assumed to be attachments. In this case, the attachment is a brochure describing all the cool things you can do in Hollyrock, as a pdf.

A leading - indicates an alternate format, like this.

edbrowse -m1 fred ^barney hollyrock-notice -hollyrock-graphical.html

html and rtf are the alternate formats that are recognized at this time. The alternate file should have the appropriate suffix. The basic file and the alternate file are sent together in one email, but when Fred receives it, his mail client will present the html version, with links to click on, forms to fill out, etc. This is practically the industry standard for email nowadays. Probably 90% of the emails you receive include an html format, even if you don't need to interact with them at all. They present graphics and images, and it's good for advertising. However, for me personally, I can probably count on one hand the number of times I've sent out an email in html format.

Now let's send mail from within an edbrowse session. As before, your buffer must contain a subject line, indicated by the keyword subject, case insensitive, followed by a colon. It must also contain a to: line, to specify a recipient. You can specify many recipients, one per line. Use cc for carbon copy, and bcc for blind carbon copy. attach: indicates an attachment. Here is a simple example.

To: fred.flintstone@bedrock.us
CC: barney.rubble@bedrock.us
attach: hollyrock-brochure.pdf
Subject: Hollyrock Vacation
Come visit Hollyrock.
It's fun, and you don't even need Gazoo.
Brochure attached.
Sincerely,
Rock studios incorporated.

If your buffer looks like this, then type sm to send mail. The default account is used to send the mail, which is the first account in our example. You can specify the second account by typing sm2, however the result will be exactly the same. If your third account is with comcast, then sm3 will send mail through your comcast account, and replies will come back to you via comcast.

alt: hollyrock-graphical.html specifies an alternate html format, using the file hollyrock-graphical.html. You can also use another edbrowse buffer. alt:4 assumes the html version of your email is in buffer 4. This works for attachments as well, e.g. attach:7 for buffer 7. In this case the attachment has no filename. The recipient will have to give it a filename if he wants to save it.

If you have a .signature file in your home directory, edbrowse appends it to your outgoing email. Unix-like mail clients have been doing this since 1980, so there is a precedent. Signature files can be tailored to the account. sm9 uses .signature9 in your home directory, if it exists; else it defaults back to .signature.

Signature files are not appended to alternate presentations. After all, your signature file is plain ascii, while the alternate format is html or rtf, and it isn't meaningful to paste those two together. If you want a signature paragraph at the end of your html email, you have to fold it in, with the proper html tags around it.

Now let's reply to an email. First you must save it, through imap or pop3. You can only reply to a local file. There are two pathways, formatted and unformatted. An unformatted email still has all the headers that you will need to reply. Type b to browse, then re to reply, or rea to reply all. In the case of rea, all the recipients will appear at the top of your file. Some will be indicated by cc, if they were carbon copied. You can delete any of these recipients before sending your response. Of course you probably don't want to delete the first line, as that is the actual reply to address. the re command takes the file out of browse mode and turns it into a plain text file. It implicitly includes the et (edit as text) command. This supports text editing, to write your reply in the body of the message. If you want to start over from scratch, you can't just unbrowse, because it is not in browse mode any more. You must re-edit the saved mail message, perhaps by rf, browse again, and reply. Like everything else in edbrowse, you get used to it once you play with it.

If the email is already formatted, you can still type re or rea. This works best if you have retained the last line of the email, which tells edbrowse where to find the headers. It looks like Unformatted 86232.60378. These headers are stored in a .reply file in your mailbox. Once again you will see the recipient at the top, then other recipients if you replied to all, then the subject line. You can include parts of the original body, or not, as you wish, and enter your own thoughts in reply.

Whether you reply to a formatted or unformatted email, there should be a references: line just before the subject. This is not a line you should edit or delete. If you participate in a discussion list, this line is important. It tells the server that your reply is indeed a reply and that it should be linked to the referenced message. Using this information, the server maintains discussion threads. If you delete this line before sending your response, you will create a new thread, and that will confuse and annoy the other participants. So - if you are going to reply to a message on a discussion list, make sure the re command inserts the References: line, and then leave it alone. Edit the body of the email, add your comments, and send.

Sometimes the references line will have two IDs separated by white space. The first is the beginning of the thread, the message that started this topic, and the second is the comment that you are replying to directly. Again, this helps list servers organize the emails into threads. Here is an example, after the rea command.

Reply to somebody@foo.bar.com
cc: another@foo.bar.com
references: <4387A55E6AF43C4F9830C74EFECE9132022D0638@foo-bar.net>
Subject: What's in a name?
Yeah I named my kid petunia.  What's it too nya?
I've seen weirder names than that out there.

Keep some of the original email, or don't, and add your thoughts, and send. You can add an attachment if you like, to support your response. This kind of interactive process is why I usually send emails from within an edbrowse session.

If you save an email formatted, the unformatted (original) version is stored in ~/.trash/rawmail. The last line of your formatted email looks like Unformatted 12345.67890. This tells you where to find the original, unformatted message: $HOME/.Trash/rawmail/12345. You can browse the original if it is in html, and you want to follow some of its links. Or you can retrieve the original if you accidentally deleted the formatted version and you need to resurrect it. It's a good idea to run a weekly cron job to clean out the trash, to make sure raw mail does not accumulate indefinitely.

A mail descriptor can include any of these directives, to establish a default behavior.

to = address
cc = address
bcc = address
attach = file

If a recipient is specified, every mail you send through this account is copied to that designated recipient. Why would you want to do that? gmail keeps an archive of all the email you send, but most mail servers don't do that. You can use this feature to replicate that behavior. cc to yourself, and everything you send out comes back to you. Then, a filter on your mail server can direct emails from you into a sent folder. Thus the sent folder contains everything you have sent.

Annoyingly, you might get a reply twice, if somebody replies to all. Guard against this by using bcc.

Attachments in the mail descriptor are sent with every email. This is generally not recommended. However, if the account is a work account, you might want to send an image or logo with every email. That is the only practical application I know of for this feature. You should use an absolute pathname for the attachment, since you might be sending email from anywhere. For security reasons, only the filename is passed through the email, so the user will not see your directory structure.

There is no way to suppress this behavior, however, you can bypass it using a different account. Recall that there are typically two descriptors for your primary email account: one for pop3 and one for imap. Place default recipients or attachments in one of the descriptors, and not in the other. As mentioned earlier, they both send email, via smtps, in the same way; however, one applies the bcc or attach directives in its descriptor, while the other does not.

If you have a lot of accounts in your config file, to send mail in different ways, with different .signatures, and different pseudo addresses like my_name+work@gmail.com, you can write helpful functions, so you don't have to remember all the account numbers.

# Send from my work account, with corporate .signature and logo.
function:smwork {
sm7
}

Compose your email, then send via <smwork, and it vectors through your work account. Replies will come back to you through your work account.

On the shell side, aliases can make it easy to fetch or access mail from different accounts.

alias workpop="edbrowse -f6"
alias workimap="edbrowse -f7"

The sent folder, native to gmail, or perhaps maintained by you, contains mail that always comes from you, so the from field is not very helpful. This is the only time I know of where you would want to see the recipient of an email, rather than the sender.

e tsd

Shows the to field and the subject and date - whom did you send the message to and what was the subject and date?

Function to go to an unformatted message from a formatted message

# Go to the unformatted message.
# usage: <uf
function+uf {
db0
H-
ebvar-
sw+
etmp
up
.g/^Unformatted \d{5}\.\d{5}$/f.w-1@$
if(?) {
/^Unformatted \d{5}\.\d{5}$/fw-1@$
}
down
s/^Unformatted \(\d{5}\).*/\/.Trash\/rawmail\/$1/f
0r !echo $HOME
j
nostack g
if(?) {
^
p not found
}
}

Function to convert the HTML part of a multipart message to an attachment

If an unformatted message is a multipart message with plain text and HTML parts, you might want to browse just the plain text part or browse the plain text and HTML parts in separate sessions. You can use this function to treat the HTML part as an attachment.

# Convert the HTML part of a message into an attachment.
# usage: <ahp
function+ahp {
ub
if(?) {
}
1X
/Content-Type:.* *text\/html/ifX
if(*) {
/^$/X
s/^/Content-Disposition: attachment; filename="message.html"\n/f
bw
}
b
}

Functions to quote a message when replying

If you have already used the re or rea commands to start a reply to a message, you can quote the message with the qm function. You can use the re function to issue the re command and then quote the message. You can use the rea function to issue the rea command and then quote the message.

# Quote the message.
# usage: <qm
function+qm {
1X
/^$/fX
+,$s/^/> /f
1X
/^$/X
}

# Start a reply and quote the message.
# usage: <re
function+re {
re
<qm
}

# Start a reply to all and quote the message.
# usage: <rea
function+rea {
re
<qm
}

Function to generate the text part of a multipart message from the alternative part

# Generate the plain text part of a multipart message from the alternative part.
# usage: <gtp
function:gtp {
db0
H-
sw+
e/temporary buffer for function gtp to use
if(*) {
eret
p temporary buffer already exists
} else {
$X
/^Alt:/ifX
if(*) {
.g/^Alt: *\d{1,4} *$/ifX
if(*) {
etmp
f temporary buffer for function gtp to use
up
enum
eret
down
eret
w/temporary buffer for function gtp to use@$
eret
} else {
etmp
up
.w-1@$
down
s/^Alt: *//if
nostack g
}
fll=72
b
up
/^Sub\(ject\)?:/ifX
r-1
down
,A
1X
if(*) {
g/^<br><a href=/f .,/^<\/a>$/j
v/^<br><a href=/f s/:\([^:]*\)$/:\n$1/f
,s/^<br><a href='\([^']*\)'>\(.*\)<\/a>$/$2:\n$1/f
,s/&apos;/'/gf
,s/&amp;/\&/gf
up2
s/$/\n\nLinks:\n/f
r-2
} else {
up2
}
}
}
}

Function to open the address book

You can use the adbook keyword to specify an address book in your configuration file. You can use this function to open this address book.

# Open address book.
# usage: <ab
function+ab {
db0
H-
bw
e -c
if(?) {
enew
nostack e -c
}
sw+
/^\s*adbook\s*=\s*/fX
if(*) {
s/^\s*adbook\s*=\s*//f
.g/^~/fX
if(*) {
s/^~//f
-r !echo "$HOME"
j
}
bw
nostack g
} else {
p no address book found
^
}
}

Function to add the sender of a message to the address book

You can use this function to add the sender of a message to your address book. Specify an alias for this email address as an argument to the function.

# Add sender to address book.
# usage: <aab <alias>
function+aab {
db0
etmp
up
H-
sw+
/^Reply to /f w-1@$
?^From ?f w-1@$
if(?) {
}
down
1s/^Reply to /~0:/
+s/^From //
if(*) {
-J:
}
<ab
r+1
w
up2
}
Clone this wiki locally