Error loading in ASP.NET Email verification URL at localhost - asp.net

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

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

Server does not support secure connections in C#

I'm getting the error "Server does not support secure connections" with my code below.
SmtpClient smtp = new SmtpClient();
MailMessage mail = new MailMessage();
mail.From = new MailAddress("*****#gmail.com");
mail.To.Add(recieverId);
mail.Subject = "Invoice Copy and Delivery Confirmation for booksap.com Order " + orderno + ". Please Share Feedback.";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(Server.MapPath("OrderMail\\Invoice.pdf"));
mail.Attachments.Add(attachment);
MailBody = "We are pleased to inform that the following items in your order " + orderno + " have been placed. This completes your order. Thank you for shopping! ";
StreamReader reader = new StreamReader(Server.MapPath("~/MailHTMLPage.htm"));
string readFile = reader.ReadToEnd();
string myString = "";
myString = readFile;
myString = myString.Replace("$$Name$$", ContactPersonName);
myString = myString.Replace("$$MailBody$$", MailBody);
mail.Body = myString.ToString();
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = true;
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("*******#gmail.com", "*******");
smtp.Send(mail);
mail.Dispose();
mail = null;
How can I fix this issue?
If I set
EnabledSsl = false
it will return the error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated.
That error message is typically caused by one of the following:
Incorrect connection settings, such as the wrong port specified for
the secured or non-secured connection
Incorrect credentials. I would verify the username and password
combination, to make sure the credentials are correct.
if it is ok,I think you have to set DeliveryMethod = SmtpDeliveryMethod.Network
simply try this..
using System.Net;
using System.Net.Mail;
var fromAddress = new MailAddress("from#gmail.com", "From Name");
var toAddress = new MailAddress("to#example.com", "To Name");
const string fromPassword = "fromPassword";
const string subject = "Subject";
const string body = "Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
ALSO
Change account access for less secure apps
Go to the "Less secure apps" section in My Account.
Try Option 2:
#Abhishek Yes.The code that you have written will send the message to the server just check your mail box (***#gmail.com) but smtp client of google is preventing you from entering into thier domain.
You have to make your gmail less secure that is you need to allow sign in attempt.
Check Your mail box,you should have such response from gmail domain and you need to make your account less secure.
I think its about captcha and bots preventing such logging in,people who know can throw some light in these things.Make your account less suspicious.Hope this helps
If you are working in any specific domain(company) then might be the company have personal proxy authentication so you will have to bypass proxy authentication for prevent error.
first you need to add
smtpServer.EnableSsl = false;
then add below code in your web.config
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy usesystemdefault="True" bypassonlocal="True" />
</defaultProxy>
</system.net>

Gmail message is rejected

I am trying to send emails from ASP.net project using "System.Net.Mail.MailMessage". I need to add about 30 contacts to "To" or "BCC" list.
It works for few recipients but when the number increases;
Gmail give error:
"Message rejected. See http://support.google.com/mail/bin/answer.py?answer=69585 for more information."
And block my accont for sending any more emails for 1 day.
How can i allow gmail to send email to many recipients?
If not what is the alternative way?
You should be able to comfortably send to 30 addresses.
I tried 40 email addresses for CC list (worked for To list as well) with the following test code,
string mailFrom = "test123#gmail.com";
string mailTo = "testccc#domain.com"; //One of your test emails
MailAddress to = new MailAddress(mailTo);
MailAddress from = new MailAddress(mailFrom);
MailMessage mail = new MailMessage(from, to);
mail.Subject = "Test subject";
mail.Body = "Hello world!!!!";
//Keep adding your emails as follows, do it in a for loop
mail.CC.Add("dhanuka1#domain.com");
mail.CC.Add("dhanuka2#domain.com");
...
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("mydev#gmail.com", "password");//Your credentials
smtp.EnableSsl = true;
Console.WriteLine("Sending email...");
smtp.Send(mail);
Console.WriteLine("Email sent...");
Console.ReadLine();

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