Using a python script, I am trying to send an email.
The mail part of the script looks like -
import smtplib
sender = 'abc.xyz#company.com'
receiver = 'abc.xyz#company.com'
message = """From: From Person <abc.xyz#company.com>
To: To Person <abc.xyz#company.com>
Subject: Inbound Folder Check - Alert
Unchanged even after an hour, please check
"""
smtpObj = smtplib.SMTP('smtp.office365.com',587)
smtpObj.starttls()
smtpObj.login('def#company.onmicrosoft.com','Password')
smtpObj.sendmail(sender, receiver, message)
The error that I am getting is -
raise SMTPDataError(code, resp) smtplib.SMTPDataError: (554, b'5.2.0
STOREDRV.Submission.Exception:SendAsDeniedE
xception.MapiExceptionSendAsDenied; Failed to process message due to a
permanent exception with message Cannot submit message. ...,
20.52176:140FCC8414001010640 10000, 20.50032:140FCC848417101069010000, 0.35180:0A006586, 255.23226:6E010000,
255.27962:0A000000, 255.27962:0E000000, 255.31418:0A00EB87, 16.55847:69000000, 1
7.43559:0000000090010000000000000D00000000000000, 20.52176:140FCC84140010100A00F 736, 20.50032:140FCC84841710100A00F836, 0.35180:8C010000, 255.23226:40000730, 25
5.27962:32000000, 255.17082:DC040000, 0.27745:9A010000, 4.21921:DC040000, 255.27 962:FA000000, 255.1494:0A00070E, 0.37692:01000100, 0.44092:01000100, 0.41232:010 00100, 0.60208:01000100, 0.37136:01000100, 0.34608:01000100, 0.55056:01000100, 0 .42768:01000100, 0.56112:05000780, 0.52807:00000000, 4.33016:DC040000, 7.40748:0 10000000000010C00000000, 7.57132:000000000000000005000780, 1.63016:32000000, 4.3 9640:DC040000, 8.45434:EC5537826FAD8844ABBA433565F1D57205000780, 5.10786:0000000 031352E32302E313232382E3032303A564931505230314D42323939303A38616433323065392D646
338612D343530642D386265322D62646464616261333932613900602005000780,
255.1750:4B01 0000, 255.31418:0A004C82, 0.22753:50010000, 255.21817:DC040000, 4.60547:DC040000 , 0.21966:B4100000, 4.30158:DC040000 [Hostname=abc]')
Only help I got on the internet was from the page - https://support.microsoft.com/en-us/help/3132755/554-5-2-0-storedrv-deliver-exception-objectnotfoundexception-mapiexcep
And it seems to say clutter is enabled but the folder is not present in the mailbox and suggests to turn off the clutter option which didn’t help.
PS - This works from my local machine within my company network but it is something to do with running it from Azure server.
First of all, please follow the offical document How to set up a multifunction device or application to send email using Office 365 to make sure whether set up correctly.
Secondly, if you were using Azure VM to send mail via SMTP, you can refer to this document Understand outbound SMTP problems in Azure VMs to try to fix your issue.
Meanwhile, for coding, there are some resources that may helps.
Python: Send Email via Office 365
Send email on App Service using Office 365 (O365) in PHP
Sending email from an Azure App Service using an O365 SMTP server in C#
Or using some packages directly like python-o365: GitHub and PyPI.
Finally, there is a service named SendGrid which be used for email service. You can use it to send mail in your scenario on Azure, please refer to the offical tutorial to know How to Send Email Using SendGrid with Azure (C#). For Python, you can code via its REST API or sendgrid python library.
Related
I'm trying to send a Google Chat message from Python in much the same way you can send a Gmail message:
https://developers.google.com/gmail/api/quickstart/python
I see documentation on how to create a Chat Bot (https://developers.google.com/chat/how-tos/bots-develop), but these typically require that you create your own https server that google can access.
I've tried using the scope 'https://www.googleapis.com/auth/chat', and it successfully goes through the authorization flow, and in particular the 'chat' scope claims to grant permissions to send messages, etc:
(see https://vizycam.com/wp-content/uploads/2022/01/Image-634-1.jpg)
I can build a request using build() and the granted credentials:
from googleapiclient.discovery import build
...
service = build('chat', 'v1', credentials=gcloud.creds())
and I can see that it has methods dms(), rooms(), spaces(), etc. that I could use to create a message, but I'm unable to get any requests to work.
Is it possible to send a chat message from a user account programmatically, in much the same way the Gmail example above does?
I am trying to send messages to my phone using the SMTP protocol. If I log into my Google Account (for which I've enabled less secure apps) I'm able to send a message to '5551234567#tmomail.net'. The subject and body of the email arrive on my phone as a text message.
However, when I try to do the same with Python's smtplib library, I don't get a message. Here's the code I'm using:
import smtplib
# Establish a secure session with gmail's outgoing SMTP server using your gmail account
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
# the account that will send the emails
server.login('me#gmail.com', 'password')
# sendmail(from, to, msg)
server.sendmail('me#gmail.com', '5551234567#tmomail.net', 'hey there!')
Does anyone know what I can do to get the text message to come through from the smtplib? Any suggestions are very welcome!
Try to check the link below.
If seems like you for forgot
server.ehlo()
How to send an email with Gmail as provider using Python?
Please let us know if you see python message in SENT emails folder of Gmail Inbox.
If yes, try to find a differences between one you sent from browser and one you sent from python API.
I'm making a script that notifies people about some pending tickets in JIRA. These notifications are sent by e-mail, I already got the notification to trigger, but I'm having problems sending the emails.
I can send them using gmail but when I tried to do it with my official account (the one that the company gave me) I am not able to send them. IT guys already provided me the 'localhost' because they use SMTP relays and the port, but they keep telling me that I should start SMTP without authentication, I'm not very sure of how to do this.
The example I found on internet was this:
import smtplib
fromaddr = 'Axel.Sa#mydomain.com'
toaddrs = ['Axel.Sa#mydomain.com']
msg = '''
From: {fromaddr}
To: {toaddr}
Subject: testin'
This is a test
.
'''
msg = msg.format(fromaddr=fromaddr, toaddr=toaddrs[0])
server = smtplib.SMTP('localhost:25')
server.starttls()
server.ehlo("mydomain.com")
server.mail(fromaddr)
server.rcpt(toaddrs[0])
server.data(msg)
server.quit()
But I keep getting this error, If someone can tell me the proper way of sending emails by SMTP without authentication I will be very grateful.
Check this stack:
How to send an email without login to server in Python
change your smtplib.SMTP('localhost:25') to smtplib.SMTP('localhost', 25)
I'm trying to use google app engine's mail service on my site. It's showing some error whenever I visit the page that sends the email. The error says that I am using an unauthorized sender for the message. Here's the code that sends the email:
mail.send_mail(sender="myapp#appspot.gserviceaccount.com",
to=input_dict["email"],
subject="Mondays user activation",
body=content)
When I try out the site locally (using dev_appserver.py) it doesn't show the error, but it doesn't send the email (Note: I have to add the --enable_sendmail option when I try it locally). The error only shows up when I publish the site.
Does anybody know what I'm doing wrong? Thanks in advance for your help!
What is myapp#appspot.gserviceaccount.com? You might not be able to send mail from that address.
App Engine applications can send email messages on behalf of the app's
administrators, and on behalf of users with Google Accounts.
The email address of the sender, the From address. The sender address
must be one of the following types:
The address of a registered administrator for the application. You can add administrators to an application using the Administration
Console.
The address of the user for the current request signed in with a Google Account. You can determine the current user's email address
with the Users API. The user's account must be a Gmail account, or be
on a domain managed by Google Apps.
Any valid email receiving address for the app (such as xxx#APP-ID.appspotmail.com).
Any valid email receiving address of a domain account, such as support#example.com. Domain accounts are accounts outside of the
Google domain with email addresses that do not end in #gmail.com or
#APP-ID.appspotmail.com.
https://developers.google.com/appengine/docs/python/mail/sendingmail
First follow these steps
https://cloud.google.com/appengine/docs/python/mail/#who_can_send_mail
Then you need to manually add the sender email in cloud console
How to add an authorized sender
You may also have to add the email address you which to send the email from to the App Engine application settings Email API authorized senders.
See https://cloud.google.com/appengine/docs/python/mail/#Python_Sending_mail
Add the unauthorized email address as an administrator here:
https://console.developers.google.com/project/_/permissions/projectpermissions
I am trying to send a mail from my web2py app hosted on GoogleAppEngine. But it is not working. I used the mail function that was given with the web2py. Does anybody how to do this?
I read in the GAE Documentation that python mail library would not work with GAE and GAE mail library has to be used. Does it also applies to web2py mail?
Thanks
The web2py gluon.tools.Mail class (that is used by the Auth module too) works on GAE and non-GAE out of the box. You just need to pass the correct settings:
mail=Mail()
mail.settings.server="smtp.example.com:25" or "gae"
mail.settings.sender="you#example.com"
mail.settings.tls=True or False
mail.settings.login="you:password"
It supports multiple encodings, MIME and attachments.
The web2py gluon.tools.Mail class works on GAE.
See code snippet gluon.tools
line 310
try:
if self.settings.server == 'gae':
from google.appengine.api import mail
result = mail.send_mail(sender=self.settings.sender, to=to,
subject=subject, body=text)
This is the correct settings to work on GAE
mail=Mail()
mail.settings.server="gae"
mail.settings.sender="you#example.com" #This must be the email address of a registered
#administrator for the application, or the address
#of the current signed-in user.
mail.settings.login="you:password"
See
http://code.google.com/intl/en/appengine/docs/python/mail/emailmessagefields.html
sender
The email address of the sender, the From address. This must be the email address of a registered administrator for the application, or the address of the current signed-in user. Administrators can be added to an application using the Administration Console. The current user's email address can be determined with the Users API.
Sorry! My english is very poor. I hope to help.
Celso Godinho (celso.gcosta#gmail.com)
Brazil World Cup champion soccer 2010
You should use the native App Engine mailer:
http://code.google.com/appengine/docs/python/mail/sendingmail.html