pythonemailsmtpipv6outbound

SMTP outbound : spoof ipv4 Receiver from


SMTP outbound traffic, how is it possible to hide the ipv4 in the email sent ?

I'm sending emails using ipv6 :

    import smtplib
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText

    smtpserver = smtplib.SMTP("smtp.gmail.com", 587, source_address=("2a00:b700:5::1:1fe",0, 0, 0))
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.login('mygmail@gmail.com', 'mypwd')
    msg = MIMEMultipart('alternative')
    msg['Subject'] = "Good Morning"
    msg['From'] = 'mygmail@gmail.com'
    msg['To'] = "receipient@gmail.com"
    MIMEText("Hello", 'html')
    msg.attach(part2)
    smtpserver.sendmail(msg['From'], "receipient@gmail.com", msg.as_string())

The receiver got the email source like that :

enter image description here

from : [IPv4] ([ipv6])

How can i hide [IPv4] using domain for example ? i've seen on a php application that they hide IPv4 using a domain for example : abc.xyz (even without owning this domain)

So their message source is like : from : [Domain] ([ipv6])


Solution

  • Use the local_hostname argument to smtplib.SMTP() to override the default hostname.

    smtpserver = smtplib.SMTP("smtp.gmail.com", 587, local_hostname = 'spoofed.exxample.com', source_address=("2a00:b700:5::1:1fe",0, 0, 0))