I have a Colab task for data processing.
I want to send a Gmail notification when this task is finished.
Can anyone help me?
You can use smtplib to send an email. For more details goto this link.
import smtplib
sender = 'from#fromdomain.com'
receivers = ['to#todomain.com']
message = """From: From Person <from#fromdomain.com>
To: To Person <to#todomain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
try:
smtpObj = smtplib.SMTP('mail.your-domain.com', 25)
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
Related
I am using CI library to send an email using Sendgrid smtp.
but it is not giving any response, neither email is sending.
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.sendgrid.net';
$config['smtp_user'] = 'api key name';
$config['smtp_pass'] = 'api key';
$config['smtp_port'] = '587';
$config['smtp_keepalive'] = 'TRUE';
$this->email->initialize($config);
$this->email->from('test#test.com', FROM_NAME);
$this->email->to($email);
extract($arr_var);
$sub=addslashes($row['subject']);
eval("\$subject= \"$sub\";");
$body=addslashes($row['message']);
eval("\$message= \"$body\";");
if ($subject!='') {
$this->email->subject(stripslashes($subject));
} else {
$this->email->subject($row['subject'].' - '.$this->config->item('app_title'));
}
$this->email->message($message);
$bool=$this->email->send();
Using above code i am sending en email CI v3 but it I am not receiving any email?
Twilio SendGrid developer evangelist here.
Two things stand out to me here.
First, where you set the smtp username, it should be the string "apikey" (see the instructions for sending with SMTP here).
Second, the from address you are sending from is "test#test.com". SendGrid requires you to verify the identity you send from. You either need go through Single Sender Verification or Domain Authentication and then use an email address that you have verified to send the emails from.
Once you have sorted those two bits out, your emails should send successfully.
I am using MailKit to reply to an email received from a Gmail account. I set the value of the In-Reply-To and References header as described in the MailKit documentation:
if (!string.IsNullOrEmpty(replyMessage.MessageId)) {
message.InReplyTo = replyMessage.MessageId;
foreach (var id in replyMessage.References) {
message.References.Add(id);
}
message.References.Add(replyMessage.MessageId);
}
Given this, I expect the reply mail to show up in Gmail as a reply to the original message. However, this does not happen. The mail is shown like any other random new mail.
Am I missing something?
You also need to set to message.Subject to “Re: “ + replyMessage.Subject
what sort of python script/function/library would allow you to send emails through any webmail service, be it gmail, yahoo, hotmail, email from your own domain etc.?
I found several examples relating to the single cases (mostly gmail), but not an all-encompassing solution.
Ex.: user inputs username, password, webmail service, then can send an email from within the python program.
Thanks.
Well, you can see some examples of how to do it here: http://docs.python.org/3/library/email-examples.html
Otherwise, you can try this:
from smtplib import SMTP_SSL as SMTP
import logging, logging.handlers, sys
from email.mime.text import MIMEText
def send_message():
text = '''
Hello,
This is an example of how to use email in Python 3.
Sincerely,
My name
'''
message = MIMEText(text, 'plain')
message['Subject'] = "Email Subject"
my_email = 'your_address#email.com'
# Email that you want to send a message
message['To'] = my_email
try:
# You need to change here, depending on the email that you use.
# For example, Gmail and Yahoo have different smtp. You need to know what it is.
connection = SMTP('smtp.email.com')
connection.set_debuglevel(True)
# Attention: You can't put for example: 'your_address#email.com'.
# You need to put only the address. In this case, 'your_address'.
connection.login('your_address', 'your_password')
try:
#sendemail(<from address>, <to address>, <message>)
connection.sendmail(my_email, my_email, message.as_string())
finally:
connection.close()
except Exception as exc:
logger.error("Error sending the message.")
logger.critical(exc)
sys.exit("Failure: {}".format(exc))
if __name__ == "__main__":
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
send_message()
You can send E-Mails via any webmail (that supports SMTP) with the smtplib module. That looks like this:
import smtplib
import getpass
servername = input("Please enter you mail server: ")
username = input("Please enter your username: ")
password = getpass.getpass() # This gets the password without echoing it on the screen
server = smtplib.SMTP(servername)
server.login(username, password) # Caution this now uses plain connections
# Read the documentations to see how to use SSL
to = input("Enter your destination address: ")
msg = input("Enter message: ")
message = "From: {0}#{1}\r\nTo: {2}\r\n\r\n{3}".format(username, servername, to, msg)
server.sendmail(username+"#"+servername, to, message)
server.quit
Please note that this example is neither clean nor tested. Look at the documentation for more information. Also it is very likely that you need to adjust a lot of stuff depending on the server you want to connect with.
For creating the message it's a good idea to look at the email module.
I have a Google Apps spreadsheet that is filled by user-submitted forms. I'm trying to write a script that verifies that the Email field filled by the users is valid. I'm using MailApp to send a confirmation email and catching errors, like this:
try {
MailApp.sendEmail(address, subject, message, {'htmlBody':htmlMessage, 'noReply':true});
Logger.log("Sending email to " + address);
} catch(e) {
return "Failed: Invalid address";
}
This works fine for immediate errors (null or malformed addresses), but not for non-existing email addresses. To catch those, until now I used the following code to wait 5 seconds and then check the inbox for Mail Delivery Notification emails:
Utilities.sleep(5000);
var threads = GmailApp.search("is:unread subject:\"delivery status notification\" " + address);
if (threads.length > 0) {
return "Failed: Delivery failed. " + threads[0].getPermalink();
}
This worked fine last year when I used it last, but trying now, I don't get the mail delivery notifications messages anymore when sending mail via script - apparently Google changed something, and now only manually sent messages receive the notification.
So given that my previous method has stopped working, does anyone have any idea of an alternative, automated method to verify the emails work?
One of our departments is requesting to receive a notification whenever an email is sent to a particular inbox. So every time an email is sent to mailbox#mycompany.com, they want an email sent to a distribution list saying "A message has arrived."
Is this possible in Exchange 2007 using a Powershell script?
Sounds to me like this is just a matter of creating a rule in Exchange.
Running through the "Rules Wizard":
Check messages when they arrive
through the specified account (select account associated with mailbox#mycompany.com)
run a script (something that will send out the new "A message has arrived." email)
OR forward/redirect it to people or distribution list
Use a transport rule
$condition = Get-TransportRulePredicate From
$condition.addresses = 'someone#contoso.com'
$action = Get-TransportRuleAction CopyTo
$action.addresses = 'otherperson#contoso.com'
New-TransportRule -Name "Notify New Message Recieved" -Conditions $condition -Actions $action