I'm having trouble defining a message in the Gmail login code when the credentials are wrong.
def connect():
imap_host = 'imap.gmail.com'
email = 'cryp#gmail.com'
password = input("Password: ")
M = imaplib.IMAP4_SSL(imap_host)
M.login(email, password)
try:
os.system('cls')
print('Connected.')
except imaplib.IMAP4.error:
os.system('cls')
print('Failed to connect.')
connect()
Below is the message that appears.
raise self.error(dat[-1])
imaplib.error: b'[AUTHENTICATIONFAILED] Invalid credentials (Failure)'
and not this:
print('Falha ao Conectar.')
The message Connected appears correctly when I type the email and password correctly, however when I make an error this message appears instead of Failed to connect.
Related
I'm using currently Grafana version: v7.1.1
I would like to configure the email alerts in the config folder of Grafana, I followed the steps I found online but I did not manage, I get an error every-time I try to send a test email
Failed to send alert notifications
here's the smtp from defaults.ini that I found in config:
##############################################
host = smtp-mail.outlook.com:587
user = my.name#hotmail.com
password =xxxxxxxxxxx
;cert_file =
;key_file =
skip_verify = false
from_address = my.name#hotmail.com
from_name = Grafana
ehlo_identity =
startTLS_policy =
##########################################
when I checked the error log, I found the following:
error="Failed to send notification to email addresses: my.name#hotmail.com: dial tcp 52.97.163.2:995: i/o timeout"
Can anyone tell me if I'm doing something wrong here? or how I can fix it?
Thanks
I want to ckeck if an URL can be reached or not, otherwise I print an error message to the user.
Here is my code
URL url = new URL("http://127.0.0.1:8080/booksManager");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
System.out.println(connection.getResponseMessage());
This code throws an error and doesn't print anything on the console.
error logs
In my lab smtp server is blocked.I had gone through the EAsendmail package but i couldn't succeed in sending email from the application directly without using going through smtp server.
here is the code
SmtpMail oMail = new SmtpMail("TryIt");
SmtpClient oSmtp = new SmtpClient();
//Set sender email address, please change it to yours
oMail.From = "yaswanthmdh#gmail.com";
//Set recipient email address, please change it to yours
oMail.To = "manojsr6#gmail.com";
//Set email subject
oMail.Subject = "direct email sent from c# project";
//Set email body
oMail.TextBody = "this is a test email sent from c# project directly";
//Set SMTP server address to "".
SmtpServer oServer = new SmtpServer("");//173.194.40.246,"74.125.237.181");
//Set 465 port
oServer.Port = 465;
//detect SSL/TLS automatically
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
//Gmail user authentication
//For example: your email is "gmailid#gmail.com", then the user should be the same
oServer.User = "yaswanthmdh#gmail.com";
oServer.Password = "";
try
{
Console.WriteLine("start to send email directly ...");
oSmtp.SendMail(oServer, oMail);
Console.WriteLine("email was sent successfully!");
}
catch (Exception ep)
{
Console.WriteLine("failed to send email with the following error:");
Console.WriteLine(ep.Message);
}
after running this code i am getting timeout error.
is there any other way to send an email other than through smtp?
is there any way to send an email from application through http?
No. That's how email works. Just like you need a web server to serve web pages, you need an SMTP server to send email. You'll have to talk to your IT Infrastructure department, and get them to either set something up for you or allow requests to whatever SMTP server you're trying to use.
If you just need to test sending email, you can use something like Papercut, for the time being, and then depending on where and how you deploy your application in production, it may no longer be a problem.
I am trying to read emails from my inbox using javamail and I am specifically checking for emails that have the subject "Delivery Status Notification". Here's the code:
for(Message message:messages){
for(Address a:message.getFrom()){
if(message.getSubject().equalsIgnoreCase("Delivery Status Notification")){
Multipart mp=(Multipart)message.getContent();
for(int i=0;i<mp.getCount();i++) {
BodyPart bodyPart = mp.getBodyPart(i);
if (bodyPart.isMimeType("text/*")) {
String cont = (String) bodyPart.getContent();
System.out.println("Content: "+cont);
}
}
System.out.println("-----\n");
}
}
The problem is that the sender of these notifications is the "Mail Delivery System" and the line
Address a:message.getFrom()
throws the error -- " javax.mail.internet.AddressException: Local address contains control or whitespace in string ``Mail Delivery System'' ".
How do I parse this address without having to catch the exception and then work with it?
Thanks for any help.
Some mail servers send these delivery notification messages using a bogus and illegal From address. You should, of course, report this bug to the mail server vendor.
While you're waiting for the vendor to fix their problem, you can work around it in JavaMail by setting the following Session property:
session.setProperty("mail.mime.address.strict", "false");
session.setProperty() was unrecognized in my case. I used below implementation and it worked!
Properties props = new Properties();
props.put("mail.mime.address.strict", "false");
Session session = Session.getDefaultInstance(props);
I try to send messsage to rabbitmq-server:
send_message(Channel, Host, Password, Message) ->
amqp_channel:cast(Channel, #'basic.publish'{exchange = <<"">>},
routing_key = <<"test">>,
#amqp_msg{payload = Message}).
But get error:
Error in process <0.431.0> with exit value:
{function_clause,[{gen_server,cast, [2,{cast,{'basic.publish',0,<<0
bytes>>,<<7 bytes>>,false,false},
{amqp_msg,{'P_basic',undefined,undefined,undefined,undefined,undefined,undefined,
undefined,undefined,undefined,undefined,undefined...
How can i fix it? How can i correctly send message to rabbitmq-server?
Thank you.
Check the value of Channel: from the stacktrace it shows that it is equal to 2, which is not a valid Pid.
The code calling send_message/4 must do something funky and not pass a valid Channel to it.