System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated in linux - linux

Hi i want send a mail from my linux server my code block/project is working in my local(windows) but i get this error when i run my project in linux.
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
Here is my code block where is my problem? thanks.
string domain = "my.local";
string userName = "info";
string userPass = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("AkXyz2*"));
string host = "mail.mymail.com.tr";
string fromMail = "mymail#mymail.com.tr";
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
var smtp = new SmtpClient(host, 587);//port
smtp.EnableSsl = true;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(userName, userPass, domain);
smtp.Credentials = credentials;
smtp.ServicePoint.Expect100Continue = false;
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
...
...
smtp.Send(mail);

Related

YesodAuth Google OAuth2 timing out

I'm trying to set up Authentication and Authorization for my Yesod website according to the book.
However, once I set up my Google OAuth2, I get a timeout:
HttpExceptionRequest Request {
host = "accounts.google.com"
port = 443
secure = True
requestHeaders = [("Content-Type","application/x-www-form-urlencoded")]
path = "/o/oauth2/token"
queryString = ""
method = "POST"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
proxySecureMode = ProxySecureWithConnect
}
ConnectionTimeout
I tried using yesod-auth-oauth2 instead, but I still got a timeout error:
HttpExceptionRequest Request {
host = "www.googleapis.com"
port = 443
secure = True
requestHeaders = [("Content-Type","application/x-www-form-urlencoded"),("Authorization","<REDACTED>"),("User-Agent","hoauth2"),("Accept","application/json")]
path = "/oauth2/v3/token"
queryString = ""
method = "POST"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
proxySecureMode = ProxySecureWithConnect
}
ConnectionTimeout
I have the Google+ API and Contacts API enabled for the web application. I'm running my website locally right now, and have my Authorized redirect URIs as
http://localhost:3000/auth/page/google/callback
http://localhost:3000/auth/page/googleemail2/complete
Turns out for my case, it was due to the IPv6 address of www.googleapis.com being filtered out by Cisco AnyConnect Socket Filter.
For instance, in the connection package, I Debug.Trace.trace'd addrs in the resolve' function to find out that the server was trying to connect initially to the IPv6 address, then the IPv4 one. Connecting to the IPv4 addresses (e.g. using ping or telnet) worked, but the IPv6 address did not, so ultimately it was a firewall issue.

O365 smtp as relay implementation

I am using the below lines of code to send an email but I get the error as 'smtplib.SMTPAuthenticationError: (535, b'5.7.3 Authentication unsuccessful' . This must be due to MFA. what can I do to authenticate?
import smtplib, ssl
port = 587 # For starttls
smtp_server = "smtp.office365.com"
sender_email = "myemail#companycom"
receiver_email = "myemail#companycom"
password = input("Type your password and press enter:")
message = """\
Subject: Hi there
This message is sent from Python."""
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo() # Can be omitted
server.starttls(context=context)
server.ehlo() # Can be omitted
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)
The solution to this issue is to manage the app password in your account or request for service accounts to your admin which doesn't have MFA.

send the emails using my gmail account in python?

I m trying to send emails to my users through my Gmail account but it does not work although my Gmail login credentials are also correct but it gives an error
Here is the code for Email Sending!
if request.method == 'POST':
EmailAddress = request.form['Emails']
Subject = request.form['Subject']
Message = request.form['Message']
EmailList = EmailAddress.split(',')
Message = 'Subject: {}\n\n{}'.format(Subject, Message)
for EmailName in EmailList:
Server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
Server.ehlo()
Server.login(UserEmail, UserPassword)
Server.sendmail(UserEmail, EmailName.strip(), Message)
response = "Success"
Server.quit()
Error:-(535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials t21sm2044741ejr.68 - gsmtp')

X509Certificate2 - The remote server could not returned.(502) Bad Gateway

I am passing ssl cerificate to client using httpwebrequest. I am getting below error. Here is the code.
string url = "htttps:\\localhost:1990\api";
string certpath = "C:\Sagar\certi.pfx";
Httpwebrequest req = (Httpwebrequest) WebRequest.Create(url);
X509Certificate2 cert = new X509Certificate2(certPath, password);
req.ClientCertificate.Add(cert);
StreamWriter sr = new StreamWriter(req.GetRequestStream());
// this line raises exception "The remote server returned error: (502) bad Gateway."
sr.write(requestBody);

Want to receive bounce back emails on my gmail account

I am using phpmailer class to send email from my server. Below is my code, i am able to send email with this code to valid email address. I want to receive bounce back emails on my email address farazaleem#gmail.com but i am not receiving any email when i send email to invalid email account like dsfsdfdsfsfsfsfs#rtretreert.com
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPKeepAlive = true;
$mail->Host = "smtpout.secureserver.net";
$mail->Port = 25;
$mail->Username = "xxxxxx#mydomain.com";
$mail->Password = "xxxxxxx";
$mail->SetFrom('farazaleem#gmail.com');
$mail->Subject = "Email body";
$mail->Sender = 'farazaleem#gmail.com';
$mail->MsgHTML($email_details);
$mail->AddAddress($entered_person_email, $full_name);
$mail->Send();

Resources