INTRODUCTION Hello, my name is Amin Bandali, and today I'd like to talk about reading and writing emails in GNU Emacs using Gnus specifically. Gnus has had this sort of reputation of being difficult to approach and configure. That's understandable because it has many, many options and major and minor modes that interact in different ways with each other. And it also doesn't help that Gnus started originally as a newsreader rather than a mail client. So a lot of the terminology that it uses is also rooted in that, in reading and writing news. But nevertheless, with this video and talk, I hope to provide a sort of very quick introduction of starting to use Gnus to read and write email and send it. We will use Gnus' IMAP support, mainly because a lot of people these days have email accounts with mail service providers that support IMAP, which is an open standard. So it's widely available and supported across many different providers as well as mail clients or mail user agents as well. DEMO Okay, so let's just jump straight right in. I will enter this demo directory that I created for the purposes of this demonstration and change my home directory to this one so that we can safely experiment with Gnus here. For this presentation, I've written up a quick initialization file or init file that I will share afterwards as well to get us going with Gnus. There's not much to it at the moment. Just set up the package archives and install the keycast package for showing the key presses in the mode line. Yeah, that's about it. And I'll also define a little like inline function +emacs.d that allows me to conveniently write and have it expanded or refer to files and directories, rather, paths that we could expand, inside my Emacs configuration directory. I also have this eval-last-sexp bound to a global key, so that I will be able to easily use it for this talk. Okay, let's jump right in. DON'T PANIC First things first, don't panic. And that's actually also the name of the very first node in the Gnus manual when you open it. And it's actually nice. I definitely, definitely recommend that you look through at least the very first couple of chapters of this, skim through it, and later on refer to it whenever you find something confusing or don't understand it. But yeah, we'll start with these two paragraphs here. So again, a Gnus installation is basically just a list of one or more servers and the subscribed groups from those servers and articles in those groups. You can already kind of see where that influence of a newsreader comes in. But yeah, basically what it's saying is that, you know, we have one or more servers. We can think of them as email servers. Groups can be like, we can think of them as folders or directories. And yeah, articles, those would be like our email messages. CONFIGURING SERVERS With Gnus, we can add and configure servers mainly using two variables. One of them is the gnus-select-method and the other is gnus-secondary-select-methods. The first one predates the second one and I generally don't recommend using it, because first of all, it can only point to one server, and that server, because it's the primary, then Gnus won't add a prefix to its groups, so later on, as you get into more advanced features of Gnus and, for example, want to write rules to modify your message composition in a way for certain groups, or file mail, automatically classify mail, this distinction can become confusing and annoying. My recommendation is to always and only use the gnus-secondary-select-methods. Yeah, so let's do that here. I'm gonna uncomment this portion. So here, I set the primary select method to nil, and the second one, I define an nnimap server of the nnimap backend. I give it the name ec25gnus. What I want it to do is to connect to my mail server, which is at this address, and fetch emails from it over TLS with this username. .authinfo And then the passwords or the credentials, you can put them in the .authinfo file. Normally, you would want to, for example, encrypt this file with your GPG key. But for this demonstration, I haven't. So yeah, the format is the keyword "machine" followed by the name of your Gnus server or account, followed by the word "login", then your login username, and then the password, which here it's not shown. Yeah. CONFIGURATION But before we actually set this, I'll just show you that if we like start Gnus with M-x gnus, initially, it will just show an error like this. Even if we continue, it's empty. There's not much because Gnus doesn't know where to fetch these emails from. And that's what we will configure. Excuse me. Yeah, so just for convenience, we can bind Gnus to, for example, C-c g, as I've done here. You will want to set your name and email address, like so. Here we tell Emacs that we are going to be using Gnus for reading email, because Emacs comes with other email clients as well, such as Rmail, and in fact, defaults to Rmail, so this way, we tell it to use Gnus. By default, Gnus puts its newsrc file and other files, I believe it still scatters them in a few different directories in your home directory, so it's a little bit messy. So what I prefer to do is to just put it all under the Gnus directory inside of my Emacs configuration, as I do here. Yeah, and then here we just tell Gnus to, like, don't try to bother with a generic newsrc file that would be shared with other news readers. Just want to use it for email. And yeah, so we just tell Gnus to keep all of its data inside a dedicated .newsrc.eld (for Emacs Lisp data) file instead. And we can also have Gnus not prompt us when we want to exit with q. Anyway, so let's go ahead and evaluate this. So this has been set, STARTING GNUS so if we type M-x gnus again, or hit C-c g, now we're faced with an empty buffer, and it says no news is good news, and that's actually one of the characteristics of Gnus is that by default it tries to like sort of declutter and show us a little less possible in the group buffer, meaning that if you don't have any groups with unread or marked or, like, starred messages, it will not show them. To actually see all of our groups or folders, we hit shift L or capital L, and we see that we have an inbox here, as expected. So we enter the inbox, and we see that there is an article there and it's already been marked as read. But if we mark it as unread and exit and enter Gnus again, this is what we would see. We would see that our group and then we enter it, we see our mail here. Yeah, and this is our very first email that we read in GNU Emacs here, inside Gnus. ALWAYS SHOWING GROUPS It might be useful to have Gnus always show certain groups or folders even if they don't have anything unread or marked inside of them. The way we can do that is by setting this variable gnus-permanently-visible-groups to a regular expression that describes the name of these groups. So if we launch Gnus again, this time, we see that that group is visible, even though there's no unread messages in it. READING MESSAGES When we enter a group or folder, we will see a list of all of our messages. Here, we only have one. We can press M-u or Alt-u to mark something as unread. You can press d to mark it as read. If you press just u, it'll tick the article, which is kind of the equivalent of marking the message or email as starred in other email clients such as Thunderbird. We see that when there are groups that have starred or ticked messages inside of them, Gnus will mark them with this little star here, or asterisk. This talk is just barely scratching the surface. Let's see how far... How am I doing with the time? Okay, 11 minutes already. DEBUGGING IMAP Just a couple of helpful things here, like this nnimap-record-commands variable. It's useful when you want to debug your IMAP setup with Gnus. If you set it to anything non-nil, it will log the commands that it runs to a special *imap log* buffer. And here I just set it to this init-file-debug variable, which is set to non-nil whenever you launch Emacs with the --debug-init switch, so that's pretty helpful. You want to also set your sent folder, basically, where Gnus will save a copy of the message that you just sent. Normally, I think the convention these days is, a lot of you know servers and clients use a dedicated sent folder, but with Gnus, I just prefer to use INBOX itself. Mainly because then I will have threading working for free, so I can read the entire thread of an email chain there in one place. Of course, we don't have to keep the messages in there forever. And in fact, Gnus has facilities, both manual and automated, for expiring emails into different locations or different folders. Yeah. So let's move on here. TOPICS Topics are another nice feature of Gnus. So this is useful for creating some topics and then classifying or grouping your directories there. So we will see the use of this in a moment, where, let's say, I want to add a second account to Gnus. This one I'm going to call ec25work. Let's pretend that this is my work email. So if we open Gnus now, we see that our work INBOX also shows up here. And because we enabled topic mode, we see that we have these sort of buttons like Gnus and misc here. And we can, I believe, create a topic with capital T n. We can call it personal, this one. Let's create another one, work. And then what we can do is go over the directory that we want, for example, this one, hit capital T m to move it to the personal topic, and this work one, move it to the work topic. So we can nicely classify and group our groups folders here, which is especially useful when you have hundreds of them. CUSTOMIZING MESSAGE DISPLAY Anyhow, we can customize different aspects of message display. Like for example, we can this way customize and change the order of which headers we want to see and where. So if I launch Gnus and go back to this email here, these are the headers that we see at the top. Excuse me. And with Gnus we can always We can have it show all the headers by pressing t to toggle the headers. Here we can see all the nitty-gritty and all of the headers in the message and we can toggle it back with t again. We can modify and customize the sorting with dedicated sorting functions. It comes with a number of them out of the box but we can define them as well. SENDING EMAILS Now to send emails. Let's see. We will be using message, and that's what Gnus itself uses. So I will set things up here. Let's see. Okay, so first of all, we want to have Gnus mark the messages that we write to others as read automatically, so this option does that. And then we define posting styles this way using the prefix, the name of the IMAP server. And this is how we can tell it to use what email address for the From [header] and which SMTP server to send it with. Yeah, and then gcc is where Gnus will save the copy of the messages that we write. So if we go ahead and launch Gnus again. We can go into our personal email here, hit m to compose a new message. We can prepare an email to, let's say, our work address. Hello from EmacsConf 2025 Gnus talk. Hello, this is just a test. :) Yeah, and we hit send. The sending will be done using Emacs's built-in SMTP libraries. Sometimes it can take a moment. Okay, that's it. It's done. So if we go back out and if we hit g to get new news, we should be able to see our new email there in the other account that we just sent it to. So we can come here, open it, and there we go. PLANS There is a lot to configure in Gnus, and we're just barely scratching the surface, and unfortunately I don't have the time to explain all of these but I do plan on doing a much longer running series, whether it's text or videos, showing how to configure and use a lot of these different aspects of Gnus. But yeah, here, near the end, just a couple of... quick things. I find it's nice to have message prompt us for [confirmation] that we do want to send a message. Actually, when it does that, I take another look over my email to make sure I don't have any typos. It's generally a good idea to wrap your messages around 70 or 72 characters. We do that here. We can tell Gnus to forward messages as a proper MIME part, instead of some half-broken way. This customization, the sendmail function, is how we tell Gnus with message to use the SMTP library to sending the email, and these two variables are useful for omitting our own email address when we want to send someone, like when we hit r, to reply to someone. if we configure these variables, then Gnus won't add our own address to the To or Cc, which is pretty useful. I also find it helpful to unbind C-c C-s. That's another key for sending the message [in addition to C-c C-c]. And because C-c C-d, which is very close to it on the QWERTY layout, is useful for saving a draft and then coming back to it, I don't want to accidentally hit C-c C-s, and send the message prematurely. So I unbind it. Yeah, anyway, that's about it. WRAPPING UP That's a kind of very quick tour and introduction of setting up Gnus. Here, we just configured a remote IMAP server, but we can also, of course, set up a local IMAP server such as Dovecot and point Gnus to there, and use programs like OfflineIMAP, I believe, or the mbsync program from isync package or isync project to synchronize our messages to local mail directories and then point Gnus to it. The reason we might want to use that is to always have a copy of our messages at hand so we can use offline. nnimap And why use nnimap specifically? As of now, the Maildir backend included with Gnus is very inefficient, especially when dealing with tens or hundreds of thousands of messages like some of us are. It just takes an eternity to try and index them and get going. In that case, what I recommend doing is instead of interfacing directly with Maildir, for Gnus, just install and run Dovecot, a local IMAP server, and point Gnus to that. I plan on writing tutorials or doing videos about these other aspects of configuring Gnus after the conference. That's about it for me, so I hope you find this helpful. If you have any questions, please feel free to email me at bandali@gnu.org or @kelar.org. You can take a look at my personal website where I plan on posting other Emacs and Gnus materials. And yeah, thank you for watching and I hope you enjoy the rest of the conference. Take care. captioned by sachac - many thanks!