Index: Lib/email/test/test_email.py =================================================================== --- Lib/email/test/test_email.py (revision 81980) +++ Lib/email/test/test_email.py (working copy) @@ -2397,6 +2397,9 @@ text/rfc822-headers """) + def test_make_msgid_domain(self): + eq(email.utils.make_msgid(domain='testdomain-string')[-19:], + '@testdomain-string>') # Test the iterator/generators Index: Lib/email/utils.py =================================================================== --- Lib/email/utils.py (revision 81980) +++ Lib/email/utils.py (working copy) @@ -148,13 +148,18 @@ -def make_msgid(idstring=None): +def make_msgid(idstring=None, domain=None): """Returns a string suitable for RFC 2822 compliant Message-ID, e.g: <20020201195627.33539.96671@nightshade.la.mastaler.com> Optional idstring if given is a string used to strengthen the uniqueness of the message id. + + The domain part of the Message-ID defaults to the locally defined hostname, + but can be specified explicitly. It is recommended to use the default, but + reasons to change it may include offering the choice to users of your + application or avoiding to produce Message-IDs in a valid email domain. """ timeval = time.time() utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval)) @@ -164,8 +169,9 @@ idstring = '' else: idstring = '.' + idstring - idhost = socket.getfqdn() - msgid = '<%s.%s.%s%s@%s>' % (utcdate, pid, randint, idstring, idhost) + if domain is None: + domain = socket.getfqdn() + msgid = '<%s.%s.%s%s@%s>' % (utcdate, pid, randint, idstring, domain) return msgid