sending mail in web2py - email

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.

Related

Why dose my mail lose some part of the content while being sent?

My code sends an email with received values.
My code:
self.alert = email.message.EmailMessage()
self.alert['Subject'] = my_subject
content1 = ''
content2 = 'ABCDEFGHIJ1ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJ'
self.alert.set_content(content) #content1 or content2
self.alert['From'] = my_from
self.alert['To'] = my_to
self.smtp.send_message(self.alert)
(content1 is six consecutive 가나다라마.
In any reason, I cannot type it in the above code block.. The site rejects to post that. Maybe it's not English..?)
When I give content1, the mail of the receiver shows only some part of the content.
가나다라마가나다라마가나다라마가나다
On the other hand, for content2, even though the length is much longer than content1, it shows all the characters in the received email.
content1 contains Korean.
Does the language have to do with this problem?
When I do the same thing on my Mac, it sends Korean well.
But this problem happens when I use a remote server.
Any thought is appreciated :)
I still don't know why, but after I tried with python3.6, the issue was gone.

Getting error while sending email by using Streamsets

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.

Email Error: missing or malformed local part

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...

nodejs, redis and mailparser wont parse an email

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.

Using the Microsoft SMTP Server's Dropfolder

I have set up Microsoft SMTP server so it will store all incoming email in a dropfolder.
I want to process, using c#, incoming mail based on the sender, recipient, and subject line. If possible, I also want to create a plain text preview of the email.
So, there are two parts to this problem.
I'm guessing a FileSystemWatcher
would be adequate for providing
notification of incoming mail.
How to parse the headers and body text from the .eml file; is there an existing library or any good documentation on the format?
Thanks for any help.
Yes - thats true
I used this: http://www.lumisoft.ee/lswww/ENG/Products/Mail_Server/mail_index_eng.aspx?type=info
It's a Mailserver written in C# with an API you can use without using the Mailserver
EDIT: Found a code snippet:
LumiSoft.Net.Mime.Mime m = LumiSoft.Net.Mime.Mime.Parse(mailfile);
Console.WriteLine("Read message from: " + m.MainEntity.From);
Console.WriteLine("To: " + m.MainEntity.To[0]);