i am trying to send an email by using StreamSets.
for this, i am using Directory as Source(list of receipts in the text file) and
Jython Evaluator for Processing and trash for Destination(for testing only).
when i run pipeline, running without any error. but getting error mail to my sender_email like this:
Your message wasn't delivered to com.streamsets.pipeline.stage.processor.scripting.ScriptRecord#3ea57368 because the domain 3ea57368 couldn't be found. Check for typos or unnecessary spaces and try again.
Here is my sample code:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import logging
for record in records:
try:
msg = MIMEMultipart()
msg['Subject'] = 'simple email in python'
message = 'here is the email'
msg.attach(MIMEText(message))
mailserver = smtplib.SMTP('smtp.gmail.com',587)
mailserver.ehlo()
mailserver.starttls()
mailserver.ehlo()
mailserver.login('sateesh.karuturi9#gmail.com', 'password')
mailserver.sendmail('sateesh.karuturi9#gmail.com',record,msg.as_string())
output.write(record)
mailserver.quit()
except Exception as e:
error.write(record, str(e))
Here is my error:
You're seeing this because you're using the record object as the email address - com.streamsets.pipeline.stage.processor.scripting.ScriptRecord#3ea57368 is the string value of a record instance.
If you're using text data format in the Directory origin, then you can use record.value['text'] instead of record:
mailserver.sendmail('sateesh.karuturi9#gmail.com', record.value['text'], msg.as_string())
If you're using a different data format (delimited, JSON etc), use preview to figure out which field the email address is in, and reference it the same way.
Related
I'm trying to send a mail in web2py but nothing happens.
Here is my code:
from gluon.tools import Mail
mail = Mail()
def sendMail():
mail.settings.server = 'smtp.yahoo.com:465'
mail.settings.sender = 'mymail#yahoo.com'
mail.settings.login = 'abc:password'
mail.send(to='a#gmail.com', subject='Hello', message='You've received a mail.')
Does anyone have any ideea what I'm doing wrong?
Have you tried changing your mail.send to:
mail.send(to='a#gmail.com', subject='Hello', message="You've received a mail.")
It seems like a simple SyntaxError, because you're defining your message string with a single quote, and you're using a single quote at You've, which is making `message='You' and the rest (ve received a mail....) a SyntaxError and using double quotes should fix it.
I am noticing that I get an email from my server each time an order is placed. It looks like the customer confirmation emails are not sending.
This is part of the error message:
A message that you sent contained one or more recipient addresses that were
incorrectly constructed:
=?utf-8?B?R3Vlc3Q=?= <>: missing or malformed local part
This address has been ignored. The other addresses in the message were
syntactically valid and have been passed on for an attempt at delivery.
------ This is a copy of your message, including all the headers. ------
To: =?utf-8?B?R3Vlc3Q=?= <>
Subject: =?utf-8?B?SW50ZWxsaWdlbnQgV29ya3Nob3A6IE5ldyBPcmRlciAjIDEwMDAwMDAzMA==?=
It looks like it’s only when the user checks out without registering
=?utf-8?B?R3Vlc3Q=?= <>: missing or malformed local part
The error message is quite obvious: There should be an email address between <>, but there is none. The local part is the part of the address before the #, and as there is nothing at all here, there is no local part. Thus your server is complaining.
You have to fix whatever application is trying to send mails to <> to get rid of the error.
The email address is not written in proper format, please use <>
I really don't Understand what you are trying to do. But This is what I found out playing around with this error.
$to = "'Name of Person' <email#example.com>";
$headers = "From: ".$_POST['theirName']."<".$_POST['theirEmail'].">\r\n";
$subject = $_POST['subject'];
$messageBody = $_POST['message']."\r\n ---\n This Message was sent from ".HOME." contact form.";
mail($to,$subject,$messageBody,$headers);
Notice that around the 'Name of Person' has single quotes. If you are trying to send emails with an additional name, title or anything else in front of the emails. With the single quotes will let PHP know that it is not an email but a string, and it will add the string but be ignored as an email, not giving you the error anymore.
The header where it states from does not need to have the single quotes.
=?utf-8?B?R3Vlc3Q=?= <-This line I don't know what it supposed to be doing.
But it's not an Email on the $to/$recipient and for that reason it giving the error. Once again, must have only emails: "email1#example.com, email2#example.com" other than that: 'String' with single quotes no error will produce...
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.
Working on a customised email template in CQ5, I have created in following text file under etc/notification. The workflow is triggered when a form is filled in by the user.
From: Order Brochure <order.brochures#gmail.com>
To: ${payload.email}
CC:
Subject: Order Brochures Confirmation ${payload.BrochureID}
Dear ${payload.Name},
Thank you for your Brochure Order, your reference is ${payload.orderBrochureID}.
Your email address is {$payload.email}.
Everything in this template works fine, except for the "To: ${payload.email}". Even the "Your email address is {$payload.email}" part displays the user inputted email fine. It also works if I input a static email address in "To:".
What am I doing wrong here? Below is the error in logs
Process execution resulted in an error:
javax.mail.internet.AddressException: Illegal address in string ``''
com.day.cq.workflow.WorkflowException: javax.mail.internet.AddressException: Illegal
address in string ``''
Remove the "CC:" it's attempting to parse the email address for this header and it's a null.
When you're dealing with these types of problems when the error is occurring within a CQ library. I recommend using a custom logger to assist with the troubleshooting.
Details of logging can be found at Logging - docs.day.com
Here's an example OSGi log configuration for your issue.
This error might be cumming because you are using a string as an Internet Address.
you need to typecast ${payload.email} to Internet Address.
I am using mailparser by andris(https://github.com/andris9/mailparser). I am sending an email via redis to an nodejs app. The mailparser for somereason is unable to parse it. What could be causing the issue?
The code to get the email from redis. client is an instance of node_redis Client. MailParser is andris' mailparser. The email in redis is sent via another server, to whose channel i have subscribed. The email sent, when saved in a text file and parsed using andris' test.js, gives the expected output.
client.subscribe('email1');
client.on('message', function(channel, message){
var Parser = new MailParser();
Parser.on('headers', function(headers){
console.log(headers.addressesTo[0].address);
});
Parser.feed(message);
Parser.end();
});
I found the reason for this. The input I saw receiving had \r\n converted to \n
Instead of
Parser.feed(message);
I believe you want
Parser.write(message);
I couldn't find the feed method in the documentation. I am using the write function and it's working. The message is the original unaltered email message, including headers, body, and attachments.