I already referred this post and post. Don't mark it as duplicate please.
I have 2 accounts in my outlook application ([email protected]
- default profile ,[email protected]
)
I 'am trying to send an email message from [email protected]
(which is automated email box(department email box) configured in my email box)
When I tried the below
for acc in outlook.Session.Accounts:
print(acc)
It prints both email accounts which is [email protected]
and [email protected]
However, when I do the below
outlook.Session.Accounts[0]
outlook.Session.Accounts[1]
It returns the below message
<COMObject <unknown>> #but in for loop above, it returns the name of email account
So, I finally did the below
From = '[email protected]' # I manually entered the from address
mail.To = '[email protected]'
mail.Subject = 'Test Email'
mail.HTMLBody = '<h3>This is HTML Body</h3>'
mail._oleobj_.Invoke(*(64209, 0, 8, 0, From)) # this results in error
--------------------------------------------------------------------------- com_error Traceback (most recent call last) C:\Users\user~1\AppData\Local\Temp/ipykernel_14360/3581612401.py in ----> 1 mail.oleobj.Invoke(*(64209, 0, 8, 0, From))
com_error: (-2147352571, 'Type mismatch.', None, 1)
How can I properly assign the From account?
update - smtp email script
import smtplib
from email.mime.text import MIMEText
sender = '[email protected]'
receivers = ['[email protected]']
port = 25
msg = MIMEText('This is test mail')
msg['Subject'] = 'Test mail'
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
with smtplib.SMTP('mail-innal.org.com', port) as server:
# server.login('username', 'password')
server.sendmail(sender, receivers, msg.as_string())
print("Successfully sent email")