11 thoughts on “Cara Mengirim Email Menggunakan Python”

  1. PermissionError: [Errno 13] Permission denied: ‘D:…………..

    cara mengatasinya bagaimana ya.. Terimakasih

    1. Kan sah ada di bacaan mas..
      “Sebelumnya Anda harus memastikan settingan “less secure apps” di akun gmail Anda sudah di ON kan.”

  2. mas saya mau tanya saya sudah modif itu email tapi menggunakan mode input. menjadi begini :

    #Latihan Ngirim Email pakai Python
    #
    import smtplib
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText

    epengirim = input(“Masukkan Email Pengirim: “)
    epenerima = input(“Masukkan Email Penerima: “)
    judulemail = input(“Judul Email: “)
    isipesan = input(“Isi Pesan: “)
    passwordemail = input(“Password Email: “)
    fromaddr = “{0}”
    toaddr = “{1}”
    msg = MIMEMultipart()
    msg[‘From’] = fromaddr
    msg[‘To’] = toaddr
    msg[‘Subject’] = “{2}”

    body = “{3}” .format(isipesan)
    msg.attach(MIMEText(body, ‘plain’))
    server = smtplib.SMTP(‘smtp.gmail.com’, 587)
    server.starttls()
    server.login(fromaddr, “{4}”)
    text = msg.as_string()
    server.sendmail(fromaddr, toaddr, text)
    server.quit()

    akan tetapi tidak berhasil. saya pingin kita memasukannya secara manual bukan di tulis di dalam scriptnya.

    trus 1 lagi mas jika berkenan menjawab, jika berhasil dalam memasukkan password pas di input akan berubah menjadi terhide atau menjadi tanda bintang gitu penginnya. syukur jika di jawab, salam

    1. Lebih kurang spt ini ya mas

      import smtplib
      from email.mime.multipart import MIMEMultipart
      from email.mime.text import MIMEText
      from email.mime.base import MIMEBase
      from email import encoders

      fromaddr = str(input(“Email Pengirim : “))
      toaddr = str(input(“Email Penerima : “))
      pssaddr = str(input(“Pssword Penerima : “))

      msg = MIMEMultipart()

      msg[‘From’] = fromaddr
      msg[‘To’] = toaddr
      msg[‘Subject’] = “Hello Dear”

      body = str(input(“Masukan Pesan : “))

      msg.attach(MIMEText(body, ‘plain’))

      # Lampiran, sesuaikan nama filename dengan nama di attachment
      filename = “outfile.txt”
      attachment = open(“E:\\Pythondir\\outfile.txt”, “rb”)

      part = MIMEBase(‘application’, ‘octet-stream’)
      part.set_payload((attachment).read())
      encoders.encode_base64(part)
      part.add_header(‘Content-Disposition’, “attachment; filename= %s” % filename)

      msg.attach(part)

      server = smtplib.SMTP(‘smtp.gmail.com’, 587)
      server.starttls()
      server.login(fromaddr, pssaddr)
      text = msg.as_string()
      server.sendmail(fromaddr, toaddr, text)
      server.quit()

    2. import smtplib
      from email.mime.multipart import MIMEMultipart
      from email.mime.text import MIMEText
      from email.mime.base import MIMEBase
      from email import encoders

      fromaddr = str(input(“Email Pengirim : “))
      toaddr = str(input(“Email Penerima : “))
      pssaddr = str(input(“Pssword Penerima : “))

      msg = MIMEMultipart()

      msg[‘From’] = fromaddr
      msg[‘To’] = toaddr
      msg[‘Subject’] = “Hello Dear”

      body = str(input(“Masukan Pesan : “))

      msg.attach(MIMEText(body, ‘plain’))

      # Lampiran, sesuaikan nama filename dengan nama di attachment
      filename = “outfile.txt”
      attachment = open(“E:\\Pythondir\\outfile.txt”, “rb”)

      part = MIMEBase(‘application’, ‘octet-stream’)
      part.set_payload((attachment).read())
      encoders.encode_base64(part)
      part.add_header(‘Content-Disposition’, “attachment; filename= %s” % filename)

      msg.attach(part)

      server = smtplib.SMTP(‘smtp.gmail.com’, 587)
      server.starttls()
      server.login(fromaddr, pssaddr)
      text = msg.as_string()
      server.sendmail(fromaddr, toaddr, text)
      server.quit()

  3. kenapa hasilnya kayak gini kak?
    Traceback (most recent call last):
    File “C:/Users/hp/Documents/kalkulator sederhana.py”, line 31, in
    server.login(fromaddr, “hdhhjdhjhbc”)
    File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\smtplib.py”, line 730, in login
    raise last_exception
    File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\smtplib.py”, line 721, in login
    initial_response_ok=initial_response_ok)
    File “C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\smtplib.py”, line 642, in auth
    raise SMTPAuthenticationError(code, resp)
    smtplib.SMTPAuthenticationError: (535, b’5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials r4sm11071703pgp.16 – gsmtp’)

Leave a Reply to dona alfian Cancel reply