{"id":2559,"date":"2023-09-21T17:08:10","date_gmt":"2023-09-22T01:08:10","guid":{"rendered":"http:\/\/pididu.com\/wordpress\/?p=2559"},"modified":"2023-09-21T17:08:11","modified_gmt":"2023-09-22T01:08:11","slug":"install-sendmail-with-dkim-on-raspbian-stretch","status":"publish","type":"post","link":"http:\/\/pididu.com\/wordpress\/blog\/install-sendmail-with-dkim-on-raspbian-stretch\/","title":{"rendered":"Install Sendmail with DKIM on Rasbios Bullseye"},"content":{"rendered":"\n<p class=\"has-red-color has-text-color\">21-Sep-2023 &#8212; This article was originally written about 6 years ago for Raspbian Jessie.  It has been updated to work with current versions of packages.<\/p>\n\n\n\n<p>I have a little Libre Computer Le Potato (basically a Raspberry Pi) that has recently become the host for pididu.com . It runs Raspberry Pi OS Bullseye, which is basically Debian linux. Here are the steps I followed to get Sendmail (v. 8.15.2-22) working with Domain Keys Identified Mail (OpenDKIM 2.11.0~beta2-4). I admit that this is something that most people will not need, so feel free to skip this article.<\/p>\n\n\n\n<p>First, install sendmail:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt-get install sendmail<\/pre>\n\n\n\n<p>First easy test to make sure it&#8217;s working.  Send mail to myself on the same server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sendmail -v MyAccountName@pididu.com\nsubject: testing sendmail\nhere is the body\n.<\/pre>\n\n\n\n<p>The lone dot by itself on the last line closes and sends the message.&nbsp;The -v switch above prints in verbose mode.  It&#8217;s important to watch the output carefully and note any errors or warnings.  If there&#8217;s no trouble, try a more thorough test by sending mail to the internet:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sendmail -v MyAccountName@yahoo.com<br \/>subject: testing sendmail<br \/>here is the body<br \/>.<\/pre>\n\n\n\n<p>Note that Yahoo, as many other email providers, will give an &#8220;Unresolvable RFC.5321&#8221; error if your server does not have a hostname  that matches your domain.  In my case, I had to edit \/etc\/hostname to contain pididu.com .  In the case of Yahoo, when you fail, the output will give you a link to explanations of the error messages.  Here is the <a href=\"https:\/\/senders.yahooinc.com\/smtp-error-codes\/\" data-type=\"link\" data-id=\"https:\/\/senders.yahooinc.com\/smtp-error-codes\/\">link<\/a>.<\/p>\n\n\n\n<p>Check Yahoo mail to see that the message was received.&nbsp; Note that I don&#8217;t use gmail for this test, which might reject mail from an unestablished source as spam.  If Yahoo didn&#8217;t get the message, try doing <code>tail \/var\/log\/mail.log<\/code> to look for errors.<\/p>\n\n\n\n<p>Now install opendkim:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt-get install opendkim opendkim-tools\nsudo mkdir \/etc\/opendkim\ncd \/etc\/opendkim\nsudo opendkim-genkey -s k1 -d pididu.com\n<\/pre>\n\n\n\n<p><code>k1<\/code> is the name I chose for the selector. <code>pididu.com<\/code> is my domain, but of course, you would substitute your own in its place. Two files will be generated:<br \/><code>k1.private<\/code> &#8211; private key information which should never leave the server, and<br \/><code>k1.txt<\/code> &#8211; information to add to the zone file on my DNS server. The contents of this file are<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">k1._domainkey IN TXT \"v=DKIM1\\ ; k=rsa\\ ;p=MIG ... IDAQAB\"\\;<\/pre>\n\n\n\n<p>A whole bunch of characters have been omitted above for brevity. <code>k1._domainkey<\/code> is the hostname for the record, and all the stuff between the quotation marks is the content of the record. You must add this record to your DNS server.&nbsp; With some hosts, you can enter this information yourself; with others, you must ask their technical support to enter it for you. To check that the record has been added correctly:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dig k1._domainkey.pididu.com txt +short<\/pre>\n\n\n\n<p>which should show the record previously entered.<\/p>\n\n\n\n<p>The installation of opendkim should have created an opendkim user. Verify:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">grep opendkim \/etc\/passwd<\/pre>\n\n\n\n<p>which should return something like<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">opendkim:x:129:129::\/usr\/run\/opendkim:\/bin\/false<\/pre>\n\n\n\n<p>Make sure that the opendkim user can access the key file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo chown opendkim:opendkim \/etc\/opendkim\/k1.private<\/pre>\n\n\n\n<p>Test the domain key:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo opendkim-testkey -d pididu.com -s k1 -vvv -k \/etc\/opendkim\/k1.private<\/pre>\n\n\n\n<p>Don&#8217;t worry if you get a warning that the key is not secure.  That just means that you don&#8217;t have DNSSEC in place.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo vi \/etc\/default\/opendkim<\/pre>\n\n\n\n<p>There may be a line starting with <code>SOCKET=<\/code> in there as the default. Comment that out, and uncomment the line of the form <code>SOCKET=inet:12274@localhost<\/code> .&nbsp;The port number does not have to be <code>12274<\/code> &#8211; choose one to suit yourself.&nbsp; Save and quit.<\/p>\n\n\n\n<p>Set other configuration information for opendkim:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo vi \/etc\/opendkim.conf<\/pre>\n\n\n\n<p>and edit existing lines sure that it contains<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Domain pididu.com\nKeyfile \/etc\/opendkim\/k1.private\nSelector k1\n\nSocket   inet:12274@localhost<\/pre>\n\n\n\n<p>If there is some other socket enabled, comment that line out.  Note that you don&#8217;t need to use 12274 &#8211; it could be 8891, or pretty much any relatively high number that you want.   Some other settings that I use that might help:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">LogWhy    yes\nMode      sv<\/pre>\n\n\n\n<p>Now configure sendmail to use opendkim to sign outgoing mail.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo vi \/etc\/mail\/sendmail.mc<\/pre>\n\n\n\n<p>and append this line to the end:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">INPUT_MAIL_FILTER(`opendkim', `S=inet:12274@localhost')dnl<\/pre>\n\n\n\n<p>Note that in the above, a grave accent opens the quote, and an apostrophe closes it. Also, the port (12274 in the above case) must match the port previously chosen for opendkim.<\/p>\n\n\n\n<p>In the same file, look for MASQUERADE section, and either comment out all lines, or edit the MASQUERADE_AS to name the actual domain of your sever like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnl # Masquerading options\ndnl # Roderick 20-SEP-2023 either masquerade as pididu.com,\ndnl # or comment this stuff out entirely.\nFEATURE(`always_add_domain')dnl\nMASQUERADE_AS(`pididu.com')dnl\nFEATURE(`allmasquerade')dnl\nFEATURE(`masquerade_envelope')dnl<\/pre>\n\n\n\n<p>After saving the file, run<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo su\nm4 \/etc\/mail\/sendmail.mc &gt; \/etc\/mail\/sendmail.cf\nexit<\/pre>\n\n\n\n<p>For some reason, I couldn&#8217;t run <code>sudo m4 <\/code>directly on my system, but the above worked.  Now restart sendmail.  It may take a minute or two:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo service sendmail restart<\/pre>\n\n\n\n<p>Then send another message to your Yahoo or other mail, as before. To confirm that things went well, look at the mail log for sendmail and opendkim activity:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">tail \/var\/log\/mail.log<\/pre>\n\n\n\n<p>Also, open the message under Yahoo mail, and view the &#8220;raw message&#8221; (it might be called &#8220;full headers&#8221; or something else, depending on your mail service). It should have a line something like this showing DKIM pass:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Authentication-Results: mta1319.mail.bf1.yahoo.com  from=pididu.com; domainkeys=neutral (no sig);  from=pididu.com; dkim=pass (ok)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>21-Sep-2023 &#8212; This article was originally written about 6 years ago for Raspbian Jessie. It has been updated to work with current versions of packages. I have a little Libre Computer Le Potato (basically a Raspberry Pi) that has recently become the host for pididu.com . It runs Raspberry Pi OS Bullseye, which is basically &hellip; <a href=\"http:\/\/pididu.com\/wordpress\/blog\/install-sendmail-with-dkim-on-raspbian-stretch\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Install Sendmail with DKIM on Rasbios Bullseye<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[166],"tags":[242,237,238,240,241,239,243],"_links":{"self":[{"href":"http:\/\/pididu.com\/wordpress\/wp-json\/wp\/v2\/posts\/2559"}],"collection":[{"href":"http:\/\/pididu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pididu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pididu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/pididu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2559"}],"version-history":[{"count":0,"href":"http:\/\/pididu.com\/wordpress\/wp-json\/wp\/v2\/posts\/2559\/revisions"}],"wp:attachment":[{"href":"http:\/\/pididu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pididu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2559"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pididu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}