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. And that's understand able 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 introduc tion 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. 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 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 plus emacs.d that allows me to conveniently write and have it expanded or refer to files and directories rather. 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. First things first, don't panic. And that's actually also the name of the very first no de in the GNU's 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, this installation is basically just a list of one or more servers and the subscribed groups from those servers and articles in those groups. And 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. And 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 It first of all it can only point to one server and that server because it's the primary then Gnus won't add a like 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 like file mail. Automatically classify mail. This distinction can become confusing and annoying. My recommendation is to always and only use the GNU 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 and the second one I define an NNIMAP server of the NNIMAP backend. And I give it the name EC25Gnus. And what I wanted to do is to connect to my mail server, which is at this address, and fetch emails from it over TLS with this username. 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. But before we actually set this, I'll just show youthat 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. So 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. And here we tell Emacs that we were 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. And by default, Gnus puts its user.c 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 told the news to like don't try to like bother with a like generic newsrc file that would be like shared with other news readers. Just want to use it for email. And yeah, so we just told the news 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, so if we type M-xx gnus again, or hit C-c g. Now we're faced with an empty bu ffer 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. 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. And 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. 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 asterisks. This talk is just barely scratching the surface. Let's see how far... How am I doing with the time? Okay, 11 minutes already. Okay. Just a couple of helpful things here, like this in an IMAP record, 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 like \*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 send folder like 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 send folder, but with Gnus, I just prefer to use Emacs 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, GNU's has facilities, both manual and automated, for expiring emails into different locations or different folders. Yeah. So let's move on here. 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 ac25-work. Let's pretend that this is like my work email. So if we open Gnus now, we see that our Org 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 like personal, this one. Let's create another one, Org. 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. 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. 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 like what email address for the from field 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. 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 accounts that we just sent it to. So we can come here, open it, and there we go. 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... I find it's nice to have message prompt us for configuration that we do want to send a message. 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. So we do that here. We can tell the news 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 Genoose 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. 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. 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 Offline IMAP, 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. And why use in an IMAP 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. And if you have any questions, please feel free to email me at bandali@gnu.org or at 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.