0

EDIT: This issue resolved itself as mysteriously as it began. Simply hoping it doesn't crop up again in the future.

I have a small python script that emails out a comic strip once a day to a handful of email addresses. Recently, one person on my list told me that the images are no longer displayed. I got the source of the email from her Gmail account, and for some reason the base-64 encoded section for the image in blank.

I have no idea why this is happening, and why it's happening to only one person. I get an SPF soft-fail in the Gmail headers, but I doubt that's causing it (that should happen to all the Gmail users on my list.) I don't even know what to Google to start troubleshooting this issue.

Faulty Email Source {censored items in curly braces}:

Delivered-To: {recipient}@gmail.com
Received: by 2002:ac2:555e:0:0:0:0:0 with SMTP id l30csp2647742lfk;
        Sun, 22 Mar 2020 02:12:09 -0700 (PDT)
X-Google-Smtp-Source: ADFU+vt1SopHnbnPh0tuHjbA/v3RMASeIKMyk35ZdIXqQHBr2LmtG11vVo6cI8XXxUf/emCJQjqb
X-Received: by 2002:a92:25d6:: with SMTP id l205mr14876228ill.35.1584868329096;
        Sun, 22 Mar 2020 02:12:09 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1584868329; cv=none;
        d=google.com; s=arc-20160816;
        b=o1VVDgxlMMWGRPy041qJS6LfA1LWjEB6+cbp768sLmMaOk7Q+qbCpAg0Mydf3pg/yu
         N3Nfh0Zv7vUdS6sapH0LzmcCG6YVBC/fkGboFuUeVJgVw24CcY8e1ofkMmIkWardIQie
         bNfAnebSMmIhmZ6UTrR79ggRhUglFx6EdAzNYdmpyRCxewK3/SN5JjdfW6KUQsgjQXU5
         PvJQEZZrt07eKjzq2kpNVobWBj8rOvVGpYc+fqNDOircTIF5ZTI3JIbCEkNvvEyAmZOW
         AK68xVtSpaYfInnJ0++dPkS9DhuH777f/yMz6Z0X26MjnoxiIovyYSNPfzZLdjpnC/CI
         G4nQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=date:message-id:to:from:subject:mime-version;
        bh=nXPNVg7/Z2G2UDLCbHAibUHl0oCh4sJ6yhHsm9HpP+Y=;
        b=Vl5At9J4nLzeREzg93sHypB2XO/vbNHAtRj4apOzQZHLg0XbjD3Hxv6t9+yzFn8thS
         pFnPRPCOOgyY+mp+8hTQrT5TaIlEcNC9Ay1x25X27wqcr0iBjw9xpTvjvFo1pX7jNK7E
         DvUZpdSoSmas32U0zT8DH1+jX5zX/8Ydr7aTOkVLPX6umVuyl2RNlW+mLZrPnCMkiH0Z
         jeTc88LMiczwsVwo2qsoKPDjFah+xTD7J+zqnuHr6IuMS3+s9t7dy4sbKRwlcxP4n2z4
         ZXjJbQpEEfOec36EF89By4ZHNHxLmDx/DZvPA5nv10emet1Omki9w2HF3hcaAijZDL2l
         jb1g==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=softfail (google.com: domain of transitioning {sender}@{my-domain} does not designate {my-ip-address} as permitted sender) smtp.mailfrom={sender}@{my-domain}
Return-Path: <{sender}@{my-domain}>
Received: from {my-domain} ([{my-ip-address}])
        by mx.google.com with ESMTP id 141si8443110ile.78.2020.03.22.02.12.03
        for <{recipient}@gmail.com>;
        Sun, 22 Mar 2020 02:12:09 -0700 (PDT)
Received-SPF: softfail (google.com: domain of transitioning {sender}@{my-domain} does not designate {my-ip-address} as permitted sender) client-ip={my-ip-address};
Authentication-Results: mx.google.com;
       spf=softfail (google.com: domain of transitioning {sender}@{my-domain} does not designate {my-ip-address} as permitted sender) smtp.mailfrom={sender}@{my-domain}
Received: from {my-domain} (localhost [IPv6:::1]) by {my-domain} (Postfix) with SMTP id BEFC13C00DD for <{recipient}@gmail.com>; Sun, 22 Mar 2020 05:12:02 -0400 (EDT)
Content-Type: multipart/related; boundary="===============0513549325=="
MIME-Version: 1.0
Subject: Calvin and Hobbes of the day
From: {sender}@{my-domain}
To: {recipient}@gmail.com
Message-Id: <20200322091202.BEFC13C00DD@{my-domain}>
Date: Sun, 22 Mar 2020 05:12:02 -0400 (EDT)

--===============0513549325==
Content-Type: multipart/alternative; boundary="===============1139914447=="
MIME-Version: 1.0

--===============1139914447==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

Calvin and Hobbes of the day email. Image not displayed for techical reasons. To unsubscribe, send an email to {sender}@{my-domain} with the subject "Unsubscribe please". You may briefly continue to recieve emails until the system processes your request.
--===============1139914447==
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

<img src="cid:30cbc076bf26fa38547141665a3874fc0bdc91b550d5b9523fbf033cd64d0d8b"><p>This Calvin and Hobbes was originally published on Tuesday, March 22, 1994. Enjoy!</p><p style="font-family:serif;text-size:9pt;">To unsubscribe, send an email to <a href="mailto:{sender}@{my-domain}?subject=Unsubscribe please">{sender}@{my-domain}</a> with the subject "Unsubscribe please". You may briefly continue to recieve emails until the system processes your request.</p>
--===============1139914447==--
--===============0513549325==
Content-Type: image/gif
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-ID: <30cbc076bf26fa38547141665a3874fc0bdc91b550d5b9523fbf033cd64d0d8b>


--===============0513549325==--

Example of an email that displayed properly (also sent to a Gmail account):

Delivered-To: {recipient2}@gmail.com
Received: by 2002:ac0:945c:0:0:0:0:0 with SMTP id j28csp4283482imj;
        Sun, 22 Mar 2020 02:12:06 -0700 (PDT)
X-Google-Smtp-Source: ADFU+vsBj6iMIZiI5aEUI+EaVIoyR/pGQUdx46SNDNiosv8OoI8WLTCvAYmWxdVSsUEGEThEY3kc
X-Received: by 2002:a92:4090:: with SMTP id d16mr1882262ill.200.1584868326631;
        Sun, 22 Mar 2020 02:12:06 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1584868326; cv=none;
        d=google.com; s=arc-20160816;
        b=o85d2nyxnlrJBxjPjbEIK+iBEUzip5+8qaw3AP2sf1oWPSHGUjyKSJMM9ya0nTgByo
         wn+hN60zGz/y23w7k6yp3V0gy94rP+qiMRn87bgahsdF6SOH6n2gDn1aYPFNZPCLRrgU
         UI+a3aX/qdDtw03LL8A9mj+v+TCvEyntddxWjiU2UHuXT88GLOPAwmt0PwH/wQp52nRV
         V4jnKFbGQU7A2FkzJccW1T6GgzoXejmXOcHi4z7emm4TGHNv4FxlPl/bna2X8dFo+8N5
         mHh7+ADWyy9wHATPJqPEtTXuBoE8Bri9n20IMKaPWKzpoasb5bFV14kA+cRkh/CckHr7
         3Vxw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=date:message-id:to:from:subject:mime-version;
        bh=tcCxyEZafImccO+owloPVRqzcCuM+m7me+VxZuISjGU=;
        b=e5DjPTX5Ia11uM7bKBRA+vGqkGlsYdJuv6Mxio7xhRtcxqBxxxyIZ80ludnCvWR/j8
         /B1qmGG6ZynxVlv7GTPOF4yP6qWhE2sycKf3yQ5MYZXLFmZMRSW0kcj/fjoKvd3BOOBV
         8DlZUNVvfNujZpm+7sdNHhT+xAU8EY1+9+b3R6GDEyDJzKrIgXclX9yVHsH91DDa5AC8
         WOUBH4ZrOZ0Zn5bvpSLOomqhGI4J2gZeb41zj8RjjuwPOE9LR5fmDCxNn+ajeBAbnJPG
         Ihl3jkrnuiJWcigsn38ctPw6inWglsK3dxKBTeXbrWHHeRtu9kHZnL1l9vpl93BM/LN9
         6jgQ==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=softfail (google.com: domain of transitioning {sender}@{my-domain} does not designate {my-ip-address} as permitted sender) smtp.mailfrom={sender}@{my-domain}
Return-Path: <{sender}@{my-domain}>
Received: from {my-domain} ([{my-ip-address}])
        by mx.google.com with ESMTP id k2si9367254jap.23.2020.03.22.02.12.03
        for <{recipient2}@gmail.com>;
        Sun, 22 Mar 2020 02:12:06 -0700 (PDT)
Received-SPF: softfail (google.com: domain of transitioning {sender}@{my-domain} does not designate {my-ip-address} as permitted sender) client-ip={my-ip-address};
Authentication-Results: mx.google.com;
       spf=softfail (google.com: domain of transitioning {sender}@{my-domain} does not designate {my-ip-address} as permitted sender) smtp.mailfrom={sender}@{my-domain}
Received: from {my-domain} (localhost [IPv6:::1])
    by {my-domain} (Postfix) with SMTP id 98FA73C00A7
    for <{recipient2}@gmail.com>; Sun, 22 Mar 2020 05:12:02 -0400 (EDT)
Content-Type: multipart/related; boundary="===============1535165371=="
MIME-Version: 1.0
Subject: Calvin and Hobbes of the day
From: {sender}@{my-domain}
To: {recipient2}@gmail.com
Message-Id: <20200322091202.98FA73C00A7@{my-domain}>
Date: Sun, 22 Mar 2020 05:12:02 -0400 (EDT)

This is a multi-part message in MIME format.
--===============1535165371==
Content-Type: multipart/alternative; boundary="===============1545014324=="
MIME-Version: 1.0

--===============1545014324==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

Calvin and Hobbes of the day email. Image not displayed for techical reasons. To unsubscribe, send an email to {sender}@{my-domain} with the subject "Unsubscribe please". You may briefly continue to recieve emails until the system processes your request.
--===============1545014324==
Content-Type: text/html; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

<img src="cid:30cbc076bf26fa38547141665a3874fc0bdc91b550d5b9523fbf033cd64d0d8b"><p>This Calvin and Hobbes was originally published on Tuesday, March 22, 1994. Enjoy!</p><p style="font-family:serif;text-size:9pt;">To unsubscribe, send an email to <a href="mailto:{sender}@{my-domain}?subject=Unsubscribe please">{sender}@{my-domain}</a> with the subject "Unsubscribe please". You may briefly continue to recieve emails until the system processes your request.</p>
--===============1545014324==--

--===============1535165371==
Content-Type: image/gif
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-ID: <30cbc076bf26fa38547141665a3874fc0bdc91b550d5b9523fbf033cd64d0d8b>

R0lGODlhhAMgAfcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0NDQ4O
Dg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8fHyAgICEh
ISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDExMTIyMjMzMzQ0
NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkNDQ0REREVFRUZGRkdH
R0hISElJSUpKSktLS0xMTE1NTU5OTk9PT1BQUFFRUVJSUlNTU1RUVFVVVVZWVldXV1hYWFlZWVpa
WltbW1xcXF1dXV5eXl9fX2BgYGFhYWJiYmNjY2RkZGVlZWZmZmdnZ2hoaGlpaWpqamtra2xsbG1t
{ ... snipped 1462 lines worth of base-64 encoded data ... }
/pQ29JRRfUNJrQ5VOZVPzEP3CAxVzcM3zIPr2EdJ6dRKDoxUvcND5NIWCVEsBQYYmRMg4UUuKYT9
1FBCrKQ9+MVKGsTwHERX8eRCzEMrVsM3kMMmGhUmro7jxKRBXOU8SFVM8sS4eFA2+eRZomVKBGVK
vMMuRMIglFFatoZUAVEVHMIp9MKzpANRLoQ2DEI3yWVgCuZgEmZhGuZhIuZPRgREDEwS+eRaJmZi
yos5HeUS2ZBjHmWWJBHkJMYObWb8gCYPsc9oro/6EIxN3JD8mM5okiZjFsxicqbpyJBpwolpztBr
OiZqglFWVIVr/lBqpib4uI9uug9nMmZmFuf7dqCmcp6mD2Hmc+oGpwjnZ7LJEhlnD9XmDkXOcl5m
Y/LQb87mdopnbBIRDdlQZaqmdmYndlqQUjind8KncH6nq1SnD6GnbuJnfq5lZVIJZEZmJu1mpKhl
bhLoSrhmbZxTgf7ngjJoutBngy6mbCbFFPknhA5mQAAAOw==
--===============1535165371==--

EDIT: A few of my other recipients have also reported that this has happened in the past, but it only lasted a day or two, and they didn't think much of it. (I believe they are all also Gmail users...)

EDIT: Here's a slightly stripped-down version of the code that sends the emails. There is a file called addresses.py in the same directory that has a nested array with all the email addresses on my list.

#!/usr/bin/python

from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage

import hashlib

import os
import datetime
from addresses import arrayTo # Addresses to send to

# Note: Calvin and Hobbes ran from 1985-11-18 to 1995-12-31
today = datetime.datetime.now()
comicDay = datetime.datetime(((today.year - 6) % 10 + 1990), today.month, today.day)
dateString = str(comicDay.year) + '-' + str(comicDay.month) + '-' + str(comicDay.day)

# Some definitions
for n in range(0,len(arrayTo)):
    strTo = ''
    numAddresses = len(arrayTo[n])
    for i in range(0,numAddresses): # Concatenate address array into CSV
        strTo += arrayTo[n][i]
        if i < numAddresses - 1: # Don't end with a comma
            strTo += ', '

    strFrom = '{sender}@{my-domain}'
    comicFile = '/path/to/files/picture_' + dateString + '.png'
    if os.path.exists(comicFile):

        # Open the image, assuming the image is in the current directory
        fp = open(comicFile, 'rb')
        msgImage = MIMEImage(fp.read())
        fp.close()

        # Generate a hash to use as the CID
        comicHash = hashlib.sha256(comicFile).hexdigest()

        # Create the root message and fill in the from, to, and subject headers
        msgRoot = MIMEMultipart('related')
        msgRoot['Subject'] = 'Calvin and Hobbes of the day'
        msgRoot['From'] = strFrom
        msgRoot['To'] = strTo
        msgRoot.preamble = 'This is a multi-part message in MIME format.'

        # Encapsulate the plain and HTML versions of the message body in an
        # 'alternative' part, so message agents can decide which they want to display.
        msgAlternative = MIMEMultipart('alternative')
        msgRoot.attach(msgAlternative)

        msgText = MIMEText('Calvin and Hobbes of the day email. Image not displayed for techical reasons. To unsubscribe, send an email to {sender}@{my-domain} with the subject "Unsubscribe please". You may briefly continue to recieve emails until the system processes your request.')
        msgAlternative.attach(msgText)

        # We reference the image in the IMG SRC attribute by the ID we chose above
        msgText = MIMEText('<img src="cid:' + comicHash + '"><p>This Calvin and Hobbes was originally published on ' + comicDay.strftime('%A, %B %d, %Y') + '. Enjoy!</p><p style="font-family:serif;text-size:9pt;">To unsubscribe, send an email to <a href="mailto:{sender}@{my-domain}?subject=Unsubscribe please">{sender}@{my-domain}</a> with the subject "Unsubscribe please". You may briefly continue to recieve emails until the system processes your request.</p>', 'html')
        msgAlternative.attach(msgText)

        # Define the image's ID as referenced above
        msgImage.add_header('Content-ID', '<' + comicHash + '>')
        msgRoot.attach(msgImage)

        # Send the email
        import smtplib
        smtpObj = smtplib.SMTP('localhost', 25)
        smtpObj.helo()
        smtpStatus = smtpObj.sendmail(strFrom, arrayTo[n], msgRoot.as_string())
        smtpObj.quit()
        if (smtpStatus != {}):
            # code to log this error
    else:
        # code to log this error
mister-sir
  • 124
  • 9
  • It would be helpful if you can show the python script (just the email bit) and the .html that you use for the email – AzyCrw4282 Mar 23 '20 at 01:37
  • I've attached the code (has the HTML embedded in it). The more I think about it, I'm pretty sure it's not a code issue, since it only affected some of my users, but I figure the code could be helpful to figure out exactly how the emails are supposed to be formed. I'm guessing that the emails are somehow being modified in transit (Maybe Google thinks it's spam or something?) – mister-sir Mar 24 '20 at 14:41
  • Your code LGTM. I can't tell exactly what your `` tag looks like so I would advise you to try the solutions from [here](https://stackoverflow.com/questions/21437916/html-image-not-showing-in-gmail). You may also want to do some trial and error locally to identify the root cause of this issue, again following the solutions from the link above. – AzyCrw4282 Mar 24 '20 at 17:55
  • @AzyCrw4282: Interestingly, other Gmail accounts recieve the image properly. I'm posting the source of another email that was sent to a Gmail user and displayed correctly. – mister-sir Mar 24 '20 at 19:03
  • Can' tell anything if I am honest. My only hint at the error is that your user may be using an old version of a web browser to access the Gmail. Do note that the web interface of Gmail itself does not have a version as its always up to date. So it must be to do with the browser. This is simply my theory, not an answer!!! – AzyCrw4282 Mar 24 '20 at 19:40
  • @AzyCrw4282: unfortunately, this problem occurs in different browsers, and also in email clients, both an app and Windows Mail. – mister-sir Mar 25 '20 at 22:56

0 Answers0