Python Forum
Sending email using own smtp server
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending email using own smtp server
#10
wow got it all to work, heres the end result

import smtplib
from email.mime.text import MIMEText
import subprocess

un = "robert.wild"
dom = "dc01.robo84.net"
cnp = "Password01!"

une = subprocess.run(f'powershell.exe $cred = Import-CliXml -Path C:\\python\\cred.xml; Get-aduser -credential $cred -server {dom} -identity {un} -properties * | select-object -expandproperty mail', capture_output=True, text=True, shell=False)

smtp_server = '172.17.1.5'
smtp_user = '[email protected]'
smtp_connection = smtplib.SMTP(smtp_server)
email_body = f'hello {un} your new password is {cnp} for {dom}'
email_message = MIMEText(email_body)
email_message['Subject'] = 'password change'
email_message['From'] = '[email protected]'
smtp_connection.sendmail(smtp_user, {une.stdout}, email_message.as_string())
smtp_connection.quit()
Reply


Messages In This Thread
RE: Sending email using own smtp server - by robertkwild - Jul-01-2024, 03:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Send email with smtp without using Mimetext mgallotti 0 1,348 Feb-01-2023, 04:43 AM
Last Post: mgallotti
  How to take the tar backup files form remote server to local server sivareddy 0 2,668 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  send email smtp rwahdan 0 2,431 Jun-19-2021, 01:28 AM
Last Post: rwahdan
  Sending Out Email via Python JoeDainton123 1 6,868 Aug-31-2020, 12:54 AM
Last Post: nilamo
  Including a Variable In the HTML Tags When Sending An Email JoeDainton123 0 2,668 Aug-08-2020, 03:11 AM
Last Post: JoeDainton123
  TimeOutError when trying to initiate smtplib.SMTP thecosmos 0 4,665 Jun-19-2020, 05:30 AM
Last Post: thecosmos
  Python sockets : Client sending to the server nico31780 0 3,418 May-17-2020, 07:56 PM
Last Post: nico31780
  SMTP problem MajK 6 4,663 May-09-2020, 07:47 AM
Last Post: MajK
  Sending an email with attachment without using SMTP? PythonNPC 5 5,033 May-05-2020, 07:58 AM
Last Post: PythonNPC
  Issue with text encoding ans smtplib.SMTP.sendmail() JustSomeUsername383 1 5,468 Jul-23-2019, 03:15 PM
Last Post: JustSomeUsername383

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020