0

I'm trying to set up a script on my VPS where it'll email backup files. I found that mutt seems to be the email to use for attachments, but I'm getting a weird text file appearing in each email and can't figure out why.

The text file is a few dozen bytes at the most, and is either called 1.txt with attachments or TEXT.txt without attachments.

It even happens on super simple examples like this:

echo "Test body" | mutt -s "Test subject" me@email.com

I tried it on dropmail.me and it didn't show the attachment, so I assume it's a minor issue that Yahoo processes wrongly. I had a google but couldn't find the right terms to search for, since it's only ever happened when sending email through mutt. Sending through sendmail is fine.

Here is a pastebin of the raw data of an email with no attachments.

Peter
  • 3,186
  • 3
  • 26
  • 59
  • I don't see any attachment in your pastebin; it's just a regular email message with a single line of text in the body. The X-YMailISG header looks like something which could possibly be communicating something to Yahoo behind the scenes; do things improve if you take that out? It seems harmless as per https://serverfault.com/questions/243466/what-exactly-is-a-x-ymailisg-header though – tripleee Jan 25 '18 at 05:41
  • "Yahoo does something wrong" is the understatement of the millennium anyway. – tripleee Jan 25 '18 at 05:42
  • Haha thanks for the reply. Judging from that question you linked, it looks like it's automatically added by Yahoo. I was just trying to figure the difference with a working email though, and potentially found the issue. The only thing that `mutt` has that a normal email doesn't is `Content-Disposition: inline`, and judging from [this post](https://forums.yahoo.net/t5/Temporary-Errors/Content-Disposition-inline-headers-not-being-respected/td-p/226349) (with sadly no replies), it's caused other people some issues too. Slight problem in I can only figure how to change headers and not remove them. – Peter Jan 25 '18 at 13:21
  • Yeah, that seems like a good clue. By definition, `Content-disposition: inline` is implied for text/plain and text/html but rarely spelled out; they seem to be interpreting it exactly wrong (as if it were saying `Content-disposition: attachment` which is basically the opposite). – tripleee Jan 25 '18 at 13:23
  • The simple answer seems to be "don't use `mutt`" but it's hard to find other mail programs with reliably and predictably allow you to send well-formed MIME messages. If really all you need is plain text, `mail`/`mailx` should work fine as a replacement (and some versions even allow you to put attachments if you want to, but it's not portable; there are multiple incompatible implementations. If you are on Debian, look for the [mailutils](https://packages.debian.org/stretch/mailutils) one ... I think?) – tripleee Jan 25 '18 at 13:29
  • Yeah unfortunately the entire point is for attachments haha, Vesta CP is installed so `exim4` can work for plain text emails. My friend wrote a script using `sendmail` where it composed the raw email, but again, yahoo caused issues in the attachments not showing when I tried it on my VPS. The only thing at the moment I can think of is would you happen to know if there's another header where I can clarify it's text only? I seem to be able to add new headers easily, just not modify existing. – Peter Jan 25 '18 at 13:37
  • I'll repeat what I already wrote, (some versions of) `mailx` can conveniently send attachments just like `mutt`, *probably* without adding this correct but pesky header, but you have to find a version which is known to do that and which exists for your platform. It's a morass. If not mailutils then maybe look at Heirloom: http://heirloom.sourceforge.net/mailx.html (Debian package [s-nail](https://packages.debian.org/en/stretch/s-nail) (sic)). – tripleee Jan 25 '18 at 13:51
  • Sorry I thought you were meaning it's on debian only. I'm completely new to Linux in general so just figuring it out as I go along, `mailutils` installed but `mailx` wasn't found so I'll give that a proper look later on, just seems a little buggy after trying a couple of examples. – Peter Jan 25 '18 at 14:24
  • 1
    Here's a smattering of alternatives: https://stackoverflow.com/questions/902591/how-to-attach-a-file-using-mail-command-on-linux (but really the accepted answer with `uuencode` is a throwback to the 1980s so that should be absolutely your last resort). – tripleee Jan 25 '18 at 15:28
  • Haha, well after trying heirloom, unfortunately I've found the problem even persists in the default `mail` which is a bit of a pain. Shame there's no chance to even mention it to Yahoo anywhere, looks like it's been an issue for many months. – Peter Jan 25 '18 at 23:26
  • Then I don't really see any other option than taking the shell script in one of the answers there, peeling off the `Content-disposition: inline` from that as suggested in a comment, and saving that as a simple local script. If there is a problem with that script, there are many others here, including I suspect more than one by yours truly. Googling for "cat sendmail site:stackoverflow.com" gets me many answers, some of which have the additional complication of including an inline HTML body part; but obviously just use `text/plain` instead of `text/html` – tripleee Jan 26 '18 at 05:18
  • I did originally try use my friends (sendmail script)[https://www.daco.tech/index.php/Database_backup] as it worked perfectly on his VPS for the past year, however for whatever reason when we tried it on mine, Yahoo would fail the DKIM and not show any text or attachments. To be fair though, I think the attachment issue is due to how Yahoo parses the email, and not how it receives it, as in if a fix is ever made on Yahoo's end, it should hopefully apply to the already existing emails too. – Peter Jan 26 '18 at 05:52
  • DKIM is completely unrelated to the content of the mail. The script which is now failing is not doing anything to add DKIM, and so anything with `mutt` or `mailx` is going to bump into the same issue. When you have a well-formed email, you submit the message to (the local equivalent of) `sendmail` which then proceeds to add a signature if it's configured to do that. If it's not properly *authorized* to do that, or if it adds an incorrect signature, or if it's not configured to add a signature for messages which require it, the recipient will rightfully reject the message. – tripleee Jan 26 '18 at 05:55
  • Maybe this though, or something like it. https://answers.launchpad.net/dkimpy/+question/188459 – tripleee Jan 26 '18 at 05:58
  • ... Do you really *have* to use Yahoo to receive these messages? The world would be a better place if everyone stopped using them. – tripleee Jan 26 '18 at 05:59
  • Your friend should learn why `if [ "$?" -eq 0 ]` is an antipattern. – tripleee Jan 26 '18 at 06:02
  • I think the sendmail script was failing the DKIM as I had it enabled in the DNS and it wasn't coded for it, just for some reason Yahoo really hated it. The only reason I'm sticking with Yahoo for this anyway is the 1tb of storage, since it's mainly for archiving and backup. As to that script, I think he was pretty new to coding at the time. I'm new to bash as of this week but tried (my own version)[https://github.com/Peter92/LinuxBackup/blob/master/file_backup.sh] to make it a bit more adaptable, still feel a little clueless about the weird syntax though after coming from Python lol – Peter Jan 26 '18 at 06:19
  • You really need [quoting](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) and `mktemp`. Try http://shellcheck.net/ for detailed diagnostics. – tripleee Jan 26 '18 at 06:50
  • Thanks for the link, seems really useful. Made the tweaks to keep it happy, but I guess I'll also post on codereview once I'm done to get some proper feedback on what I'm still doing wrong :) – Peter Jan 26 '18 at 16:27

0 Answers0