Sending Email is Not Working When it Hosted to server? - asp.net

Im working with email sending App.It works perfect in Local System(My system). When i hosted it into server it show me the error like "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required".
Here is My Code:
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential
("Mymail#gmail.com", "Mypwd");
smtp.EnableSsl = true;
smtp.Send(Msg);

Please try to change
smtp.UseDefaultCredentials = false
to
smtp.UseDefaultCredentials = true;
EDIT
Also try to make
smtp.EnableSsl = false;
Note: This is what I have already working mail client on the server

Related

SMTP server: too many connections and service not available

Hello my name is Prince...im trying to implement a register module to send a confirmation email to my client email address in asp.net. I'm using SMTP client to implement this. I used the following code:
using (SmtpClient smtp = new SmtpClient())
{
using (MailMessage mm = new MailMessage("onukwilip#gmail.com", Email.Text.Trim()))
{
mm.Subject = "Dummy";
mm.Body = "Body";
mm.IsBodyHtml = false;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential credit = new NetworkCredential("onukwilip2006#gmail.com", "onukwilip2006+_");
smtp.UseDefaultCredentials = true;
smtp.Credentials = credit;
smtp.Port = 587;
smtp.Send(mm);
}
}
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"Mail sent successfully\");", true);
i used the above function in my button onclick, but when i send the smtp is telling me:
Service not available, closing transmission channel. The server response was: Service not available
I've set my settings in account.google.com to allow less secure apps or something like that but the smtp is still not working.
It was telling me the below text the night before.
Service not available, closing transmission channel. The server response was: Too many connections
But now its telling me the below code this night.
Service not available, closing transmission channel. The server response was: Service not available
I also tried using the below function, but its still not working:
using (MailMessage mm = new MailMessage("onukwilip#gmail.com", Email.Text.Trim()))
{
mm.Subject = "Dummy";
mm.Body = "Body";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential credit = new NetworkCredential("onukwilip2006#gmail.com", "onukwilip2006+_");
smtp.UseDefaultCredentials = true;
smtp.Credentials = credit;
smtp.Port = 587;
smtp.Send(mm);
}
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"Mail sent successfully\");", true);
Ive changed the port to : 25, 465,587 but still gives me the same error, when i set to 465 it tells me
Failure to send mail
Ive checked google for some answers but none seems to accomplish or settle the problem. Please help me...
UPDATE: I just tried it again using smtp.gmail.com as the host and port 587. but its still telling me:
Service not available, closing transmission channel. The server response was: Server busy, too many connections

asp.net sending mail through office 365 smtp

I'm trying to set up a email notification for a asp.net project, but it doesn't seem to work. On localhost it gives me the following error
5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
while on azure it triggers a suspicious login message over and over.
I tried multiple suggestions:
port 25 instead of 587
UseDefaultCredentials true or false
enable and disable SSL
nothing seems to work. The suspecious activity mail is the closest I got so far. Here is my code
var client = new SmtpClient();
client.Host = "smtp.office365.com";
client.UseDefaultCredentials = false;
client.Port = 587;
client.EnableSsl = true;
client.Credentials = new NetworkCredential("Rachelle.XXXX#outlook.com", "password");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
var message = new MailMessage("Rachelle.XXXX#outlook.com", "Rachelle_xxxxx#hotmail.com");
message.Subject = "a ticket has been changed";
message.Body = "Hi there, a ticket has been changed on Cronos. Please check Cronos for more details";
message.BodyEncoding = Encoding.UTF8;
message.IsBodyHtml = true;
try
{
client.Send(message);
return message;
}

Error loading in ASP.NET Email verification URL at localhost

I am using smtp gmail to for email verification. It is assigned as per the standards. When a new user registers, it is able to send mail to user along with URL for verification. But on clicking the URL which the user receives, it is unable to load the page. What might be the error
the URl address is like
string url = "http://localhost:49432/EmailVerification.aspx?vcode=" + id
this is what my smtp class mail looks like
SmtpClient smtp = new SmtpClient();
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Host = ConfigurationManager.AppSettings["SMTP"];
smtp.Port = 587; // 465; //Gmail works on this port
// smtp.Port = 25;
smtp.Timeout = 100000;
smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"], ConfigurationManager.AppSettings["FROMPWD"]);
smtp.Send(objmail);
//ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "MSG", "alert('Mail Sent Sucessfully');", true);
in the webconfig file. I have given

Unable to send Emails from Remote Server using asp.net & C#?

I am able to send emails successfully from LocalHost.
After hosting my website i am unable to send.
The following is the error:
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. ha10sm40374374pbc.23 - gsmtp
can anyone help me to solve this.
Below is code:
public void SendMail(string ToMail, string subject, string Message)
{
// Gmail Address from where you send the mail
string fromAddress = "mygmailid#gmail.com";
// any address where the email will be sending
//string toAddress = ToMail;
//Password of your gmail address
const string fromPassword = "********";
// Passing the values and make a email formate to display
//string subject = subject;
string body = "\n\n"+Message;
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, ToMail, subject, body);
}
Google sent a mail with the subjact "Suspicious sign in prevented"
I selected it's me only option.
Then changed the Gmail password and used it in the application .
Now able to send the mails from the production server also...
Try below code:
using (MailMessage mailMessage = new MailMessage())
{
mailMessage.From = new MailAddress(email);
mailMessage.Subject = "YOUR_SUBJECT";
mailMessage.Body = "YOUR_MAIL_BODY";
mailMessage.To.Add(new MailAddress("RECIPIENT_EMAILID"));
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new
System.Net.NetworkCredential();
NetworkCred.UserName = "SENDER_MAIL";
NetworkCred.Password = "SENDER_MAIL_PASSWORD";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Send(mailMessage);
}
After invoking above method GOOGLE or GMAIL will send you one mail regarding security (To allow the less secure app to configure mail) then allow that one.

Sending Mail via Mail Server Asp.net mvc4

I am trying to send mail through mail server ( available in fatcow).
Username: info#efernssolutions.com
SMTP Server: smtp.hostname.com
SMTP Port: 587
I used the follwing code to send mail ,
if (ModelState.IsValid)
{
MailMessage message = new MailMessage();
try
{
message.To.Add(new MailAddress("kishore.eferns#gmail.com"));
message.From = new MailAddress("info#efernssolutions.com");
message.Subject = "Test mail";
message.Body = "this is the mail sended through my c#.net program";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.UTF8;
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.hostname.com";
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("info#efernssolutions.com", "password");// is u are using Gmail
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = nc;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
client.Send(message);
}
catch (Exception ex)
{
;
}
}
When i use gmail server the code works fine and i received mail.
But it is not working with my email server.
I get the error,
the remote certificate is invalid according to the validation procedure
Is there anything left to do to make it work?
Please help,
Thank you
As first check I will suggest to check if your SSL certificate is correctly installed on your server

Resources