1

I want to send a warning email to a user. In my company we have an exchange server, but I dont have a dedicated account for my app. So, I would like to send a message with a noreply sender or an invented sender. Is it possible? How to config the credentials/Account?

This is the code I have, but it needs to use some user's account. I would like to avoid using user's account.

from exchangelib import DELEGATE, Account, Credentials, Configuration, Message, Mailbox

creds = Credentials(
username="DOMAIN\\my.login", 
password="")

config = Configuration(server='server.company.com', credentials=creds)

account = Account(
primary_smtp_address="myemail@company.com",
autodiscover=False, 
config = config,
access_type=DELEGATE)

m = Message(
    account=account,
    subject='Daily',
    body='BOdy test',
    to_recipients=[
        Mailbox(email_address='recip@test.com'),
    ],
    cc_recipients=['cc_recip@test.com'],  
    bcc_recipients=[
        Mailbox(email_address='bcc_recip@test.com'),
    ],  
)

m.send()
O Pardal
  • 647
  • 4
  • 21
  • You could set up an SMTP relay server in Exchange and use regular email (`smtplib`) instead. – Tomalak Jun 19 '19 at 15:32
  • I have tried to use smtplib.SMTP(server, 25), but I got this message:TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.//////////// Any ideias? – O Pardal Jun 19 '19 at 15:41
  • Of course you have to set up an SMTP server in Exchange first. – Tomalak Jun 19 '19 at 15:44
  • I am not the server admin, so it wont be easy to go through this way, but thank u very much. – O Pardal Jun 19 '19 at 16:03
  • There is a chance that this is already set up. Maybe not at the IP address you expect, and maybe you need to get a username/password first. It's worth asking. – Tomalak Jun 19 '19 at 16:15
  • Man, you were right. I have discovered this smtp server. And used smtplib. Now I am struggling with this error: SMTPRecipientsRefused: {'recip@test.com': (554, b'5.7.1 : Recipient address rejected: Access denied')}. I am reading some stuff related to this, but if you have any tips I would appreciate it very much. Thanks again! – O Pardal Jun 19 '19 at 17:39
  • You normally are only allowed to send "from" Email addresses like "anything@yourcompany.com", sending "from" a different domain will be blocked. And when the server does not accept mails from you, you might not have the proper level of access there (it *is* an "access denied" message, after all). Ask your Exchange admin. :) – Tomalak Jun 19 '19 at 17:41

0 Answers0