below is the code
MailMessage message = new MailMessage();
message.From = new MailAddress("test#myDomain.com", "display name");
message.To.Add(email);
message.Body = "somebody please kill the developer";
message.Subject = subject;
SmtpClient client = new SmtpClient("mail.myDomain.com");
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("email#myDomain.com","myPassword");
client.EnableSsl = False;
client.Port = port;
client.Send(message);
1st test in my local network - success
2nd test application run at
azure server ~ application setting the same as 1st test - Got HELO error
ping and telnet from azure server is working, already double check the ip and port
Regards
Just a mediocore developer
Seems your username & password is not authenticating successfully with your SMTP server. Please check it again.
Related
I'm developing a third-party add-on to run in a program called M-Files.
The purpose of the add-on is to send a mail with the help of an SMTP server. I created a fake SMTP server in DevelMail.com just for testing.
Testing the SMTP server from a browser works but when i run the code it gives me the following error.
Transaction failed. The server response was: 5.7.1 Client host rejected: Access denied
Here are the SMTP information:
Host: smtp.develmail.com
SMTP Port: 25
TLS/SSL Port: 465
STARTTLS Port : 587
Auth types: LOGIN, CRAM-MD5
Here is the code:
MailAddress adressFrom = new MailAddress("notification#mfiles.no", "M-Files Notification Add-on");
MailAddress adressTo = new MailAddress("majdnakhleh#live.no");
MailMessage message = new MailMessage(adressFrom, adressTo);
message.Subject = "M-Files Add-on running";
string htmlString = #"<html>
<body>
<p> Dear customer</p>
<p> This is a notification sent to you by using a mailadress written in a metadata property!.</p>
<p> Sincerely,<br>- M-Files</br></p>
</body>
</html>
";
message.Body = htmlString;
SmtpClient client = new SmtpClient();
client.Host = "smtp.develmail.com";
client.Port = 587;
client.Credentials = new System.Net.NetworkCredential("myUserName", "myPassword");
client.EnableSsl = true;
client.Send(message);
Reason for the Issue:
Usually, email sending option using SMTP encountered Access denied
because there should have a sender email which required to allow
remote access. When SMTP request sent from the sender email
it checks whether there is remote access allowed. If no, then you
always got Access denied message.
Solution:
For example let's say, you want to send email using Gmail SMTP in that case you do have to enable Allow less secure apps: ON
How To Set
You can simply browse this link Less secure app access and turn that to ON
See the screen shot
Code Snippet:
public static object SendMail(string fromEmail, string toEmail, string mailSubject, string mailBody, string senderName, string senderPass, string attacmmentLocationPath)
{
try
{
MailMessage mail = new MailMessage();
//Must be change before using other than gmail smtp
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(fromEmail);
mail.To.Add(toEmail);
mail.Subject = mailSubject;
mail.Body = mailBody;
mail.IsBodyHtml = true;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(senderName, senderPass);//Enter the credentails from you have configured earlier
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
return true;
}
catch (Exception ex)
{
return ex;
}
}
Note: Make sure, fromEmail and (senderName, senderPass) should be same email with the credential.
Hope that would help.
I am trying to send an email but i am getting authentication failure.
Do we need any specific type of authentication for Google mail.
[Error in Browser][1]
// Created Mail message and taken inputs
MailMessage mail = new MailMessage(from,to,subject,message);
// Used SMTP Client
SmtpClient client = new SmtpClient();
// Google Port
client.Port = 587;
client.Credentials = new NetworkCredential(From.Text, password.Text);
client.UseDefaultCredentials = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Send(mail);
Label.Text = "Sent Successful";
I am getting error near Send(mail)
You're not setting the SMTP server address?
Assuming your credentials are correct then you should use SmtpClient client = new SmtpClient("smtp.gmail.com") and client.Port = 465. 587 is for TLS
I see many posts on SMTPClient but I'm still stuck.
I am creating a C# Console application targeting the .NET 4.0 framework and running on a Windows 2008 R2 Datacenter (server).
I want send an email using SSL from a gmail account I just created.
If I use port 587, I get an exception:
The SMTP server requires a secure connection or the client was not authenticated
If I use port 465, I get another one:
Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall.
I realize this question has been asked several times in the past. All answers I see relate to the order in which UseDefaultCredentials is set. It must be set to false BEFORE the real credentials are set. I have followed this advice (as per the code below) and yet I still get a failure.
Other answers include switching ports from 465 to 587... which i have tried and just results in a different error (as stated above).
Here's my code:
NetworkCredential credentials = new NetworkCredential("something#gmail.com", "2-step-auth-Password");
MailAddress address = new MailAddress("something#gmail.com");
SmtpClient client = new SmtpClient("smtp.gmail.com", 465); // or 587
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = credentials;
client.Timeout = 10000; // 10 seconds.
client.Host = "smtp.gmail.com";
//client.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
MailMessage message = new MailMessage("example#gmail.com", recipients);
message.Subject = "Hello";
message.Body = "Goodbye";
message.BodyEncoding = Encoding.UTF8;
try
{
client.Send(message);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString());
}
message.Dispose();
Update 2: I see another answer which may be my issue: gmail requires an application-specific password (which is apparently not available with my current gmail account. not sure why yet). but this may be my issue.
Update 3: I have followed all instructions. Generated 2-step authentication with Gmail, and still fails.
Below code works for me, you can try this:
SmtpClient smtp = new SmtpClient("smtp.office365.com");
//Your Port gets set to what you found in the "POP, IMAP, and SMTP access" section from Web Outlook
smtp.Port = 587;
//Set EnableSsl to true so you can connect via TLS
smtp.EnableSsl = true;
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("Username", "Password");
smtp.Credentials = cred;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("Sender Email Address", "Sender Name");
StringBuilder mailBody = new StringBuilder();
mail.To.Add("ToEmailAddress");
mail.Subject = "Subject";
mail.IsBodyHtml = true;
mail.Body = "Body Text";
try
{
smtp.Send(mail);
}
catch (Exception ex)
{
}
I am trying to send email in a .NET console application. I have an SMTP server with i.P. address X.X.X.X (sanitized to protect the innocent).
The SMTP server has been set up (the relay configured) to allow email from the server that is hosting the .NET console app, and send that email to the outside world.
I have tested this with telnet from the server hosting the console app. I successfully sent an email with telnet console from the server hosting the console app using the SMTP server's I.P. address. There is no authentication required when using telnet. I have not been given any connection credentials.
But when I try to do it in the .NET app, I get the following error:
Syntaz error, command unrecognized. The server response was: : Helo command rejected: need fully-qualified hostname
Here is my code:
string mailMessagetest = "test";
string subjecttest = "test";
List<string> recipienttest = new List<string>();
recipienttest.Add("me#mydomain.com");
utility.SendMail(recipienttest, subjecttest, mailMessagetest);
Here is the function SendMail:
public static void SendMail(List<string> recipient, string subject, string message)
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("myfriend#mydomain.com");
foreach (string to in recipient)
{
mailMessage.To.Add(to);
}
mailMessage.Subject = subject;
mailMessage.Body = message;
SmtpClient client = new SmtpClient();
client.Host = "X.X.X.X";
client.Port = 25;
client.Send(mailMessage);
}
Change the hostname from an IP address to its name, e.g. "smtp.provider.com" or if its internal "mailserver.domain".
UPDATE:
Try read this system.net.mail.smtpclient fqdn required and this the FQDN is not sent when you send a HELO or EHLO.
Create a user with password on your SMTP server then apply the following settings:
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("user", "pass");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Port = 25;
smtp.EnableSsl = true; // or false depending your server
I am trying to create a web application which upon entering your email address and message , sends an email with this information from the email address.
I used this:
try
{
NetworkCredential login = new NetworkCredential("your_____#gmail.com", "password");
System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage();
email.To.Add(new MailAddress("my____email#gmail.com"));
email.From = new MailAddress("your_____#gmail.com");
email.Subject = "Question";
email.Body = question;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = login;
client.Send(email);
}
catch
{
}
But its giving me an SMTP error.
"Service not available, closing
transmission channel. The server
response was: Cannot connect to SMTP
server 209.85.129.111
(209.85.129.111:25), connect error
10051" System.Exception
{System.Net.Mail.SmtpException}
To send through your gmail account, you need to connect to port 587:
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
You do not need to specify port 587 - the code works without it. I have successfully sent and received e-mail using:
SmtpClient client = new SmtpClient("smtp.gmail.com");
If you look at the error closely, it says "Cannot connect to SMTP server" and error 10051 means the network is unreachable. Do you have a firewall blocking port 587?
Gmail uses port 465 and the erros show port 25
try using 465 port
http://mail.google.com/support/bin/answer.py?answer=76147