Unable to send email when under Docker environment - windows

I'm unable to send an email when under Docker environment but if I tried running my application outside of Docker. It works.
I tried exposing the SMTP port from Docker but still failed
Here is my email function:-
SmtpClient client = new SmtpClient("myhost", 587);
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("email#example.com", "password");
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("email#example.my");
mailMessage.To.Add(email);
mailMessage.Body = "message";
mailMessage.Subject = "Subject";
mailMessage.IsBodyHtml = true;
client.Send(mailMessage);
I got a "Socket Exception: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server."

Related

Connect to Azure Storage blob Behind Proxy: The proxy tunnel request to proxy 'http://ipaddress:port/' failed with status code '407'

Follow code available on Microsoft documentation portal but what if I want add the proxy to it? I'm using .NET Core 6+
string blobstorageconnection = pConfig.AzuerBlobStorageConnectionString;
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobstorageconnection);
CloudBlobClient? blobClient = null;
CloudBlockBlob? blockBlob = null;
blobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(pConfig.AzureStorageContainerName);
blockBlob = container.GetBlockBlobReference(pFileName);
await blockBlob.UploadFromFileAsync(pFilePath + #"\" + pFileName);
I tried above code and it is working fine without proxy setting in network but as we enable the proxy setting system raise the error : "The proxy tunnel request to proxy 'http://ipaddress:port/' failed with status code '407'."

'The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required

System.Net.Mail.SmtpException: 'The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required.
using (SqlConnection con = new SqlConnection(ApplicationSettings.ConnectionString()))
{
con.Open();
//try
//{
SqlCommand cmd = new SqlCommand("SELECT [Email Address] FROM [Staff] WHERE [Access Level]='Manager'", con);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
string emailaddress = Convert.ToString(sdr["Email Address"]);
MailMessage mail = new MailMessage();
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("possystemmahdealjamil#gmail.com");
mail.To.Add(emailaddress);
mail.Subject = "Todays POS System Reports";
mail.Body = "Todays shift is closed at"+DateTime.Now.ToString();
smtpServer.Port = 587;
smtpServer.Credentials = new [enter image description here][1]System.Net.NetworkCredential("possystemmahdealjamil#gmail.com", #"###########");
smtpServer.EnableSsl = true;
smtpServer.Send(mail);
MessageBox.Show("Mail is Send Successfully ", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
//}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message, "open shift failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
//}
//finally
//{
// con.Close();
//}
}
My problem is solved, there was Security Settings Issue, for this i had to give access to the less secure app option on my sender email
I had also faced the same problem. Although I had given access to less secure app on my sender email, the problem was still not resolved. After a thorough searching and trial & error, I've changed the password of my sender email to a new one which is way stronger than the previous one. And voila! the problem was resolved.
What was really confusing that, this kind of error for weaker password usually comes with a code 5.5.1. like this:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
This may occur if the existing password does not meet the email host's password requirements. But for me the error code was 5.7.0.

Minio Received non-HTTP message from new connection

server error:
Received non-http message from new connection
client error:
code:
var endpoint = "127.0.0.1:9000";
var accessKey = "MFQD47M******R5TZ1";
var secretKey = "WsuNQtYs********npA7iMRLjRmx";
var minio = new MinioClient(endpoint, accessKey, secretKey).WithSSL();
await minio.ListBucketsAsync();
Try removing .WithSSL(). It seems like your server is expecting plain HTTP, but your client is expecting HTTPS. First try changing the client to plain HTTP. If that works, you'd probably want to properly enable HTTPS on your server so you have a secure connection.
https://docs.minio.io/docs/how-to-secure-access-to-minio-server-with-tls

PHPMailer didn't work in Windows Server 2012 - Unable to relay w/Gmail, Yahoo, etc ...

I have a problem with PHPMailer inside my Windows Server 2012. I'm using XAMPP as my local server. I notice that i cannot ping smtp.gmail.com in my window server 2012. it says
ping request could not find host smtp.gmail.com. Please check and try again
I added this line in php.ini
[mail function]
smtp_server=smtp.gmail.com
smtp_port=25
sendmail_path ="\"D:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=On
And I added this line in sendmail.ini
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=example#gmail.com
auth_password=password
force_sender=
force_recipient=
hostname=localhost
I test my PHPMailer in my local PC, it works fine. I can send into my own domain email ("example#pn.com") and other domain email such as test#gmail.com, test#yahoo.com etc. Here's my PHPMailer code.
testsend.php
<?php
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "example#gmail.com";
$mail->Password = "password";
$mail->setFrom('test#gmail.com', 'First Last');
//$mail->addReplyTo('replyto#example.com', 'First Last');
$mail->addAddress('test#gmail.com', 'John Doe');
$mail->Subject = 'PHPMailer GMail SMTP test';
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
$mail->Body = 'dfssf';
$mail->AltBody = 'This is a plain-text message body';
//$mail->addAttachment('images/phpmailer_mini.png');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
But when I add similar PHPMailer folder and files inside my server, it only work when I send to my own domain which is ("example#pn.com").It does not work with other email domain such as gmail, yahoo etc. It says
Mailer Error: SMTP Error: The following recipients failed: test#gmail.com: Unable to relay
How to fix that problem ?
Thanks.

401 error with urbanairship using httpsurlconnection class

I am getting a 401 error when i try to hit the push URL. I am using HTTP BASIC authentication with "Application Key" as username and "Application Master Secret"as password. I am using JAVA HttpsUrlConnection class. I dont know whats wrong with my code.
` URL url = new URL("https://go.urbanairship.com/api/push");
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type","application/json");
connection.setRequestProperty("Content-Length", Integer.toString(data.length()));
String authString = "xxxxxxxxxxxxxxxxxx:yyyyyyyyyyyyyyyyy";
authString = Base64Coder.encodeString(authString);
connection.setRequestProperty("Authorization","Basic "+ authString);
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(data);
wr.flush();
int responseCode = connection.getResponseCode();
//Get the response
String responseLine = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();`
Your authString should be composed of <application-key>:<application-master-secret>. Also your authstring may not be getting encoded properly. Try using Apache Commons Codec or ostermiller library to encode the authstring

Resources