not able to send email - c#

My website is hosted on a Godaddy server. I am trying to send an email but i am getting "The operation has timed out." error. I have tried following links but its not working.
GoDaddy email sending failed
and
Not Able To Send Email Via C#
I have tried so far below code.
In web.config
<system.net>
<mailSettings>
<smtp>
<network host="smtpout.secureserver.net" userName="username" password="secret" />
</smtp>
</mailSettings>
</system.net>
and in code behind
var SmtpClient = new SmtpClient();
SmtpClient.Send(frommail,tomail,subject,body);
I have also tried below code
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(txtForgotEmail.Text));
msg.From = new MailAddress("email");
msg.Subject = "subject";
msg.Body = "msg body"
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("toemail", "secret");
client.Port = 25;
client.UseDefaultCredentials = false;
client.Send(msg);
P.S. i cant even send an email from localhost and also tried
client.EnableSsl = false;
client.UseDefaultCredentials = false;

Try adding port to settings
<network host="smtpout.secureserver.net" userName="username" password="secret" port=25/>
For what ports to use refer,
https://sg.godaddy.com/help/what-do-i-do-if-i-have-trouble-connecting-to-my-email-account-319
try all 25, 80, 3535 and 465 with SSL

Related

"System.Net.Mail.SmtpException" Asp.NET

I was building a project that sends e-mails from my website to an account using SMTP with the Asp.NET Framework with MVC, but, when I try to send the e-mail it catches the next exception
The SMTP server requires a secure connection, or the client did not authenticate. The server response was: 5.7.0 Authentication Required
This is the code inside the try
MailMessage message = new MailMessage();
message.From = new MailAddress("myemailfortesting#gmail.com");
message.To.Add(new MailAddress(contact.Email));
message.Subject = "Test";
message.IsBodyHtml = true;
message.Body = "Name:" + contact.Name+ "Message:" + contact.Text;
using (SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587))
{
smtpClient.Credentials = new NetworkCredential("myemailfortesting#gmail.com", "p455w0rD");
smtpClient.EnableSsl = true;
smtpClient.Send(message);
}
The connection string in Views/Share/Web.config
<system.net>
<mailSettings>
<smtp from="myemailfortesting#gmail.com">
<network host="smtp.gmail.com" port="587" userName="myemailfortesting#gmail.com" password="p455w0rD" defaultCredentials="true" enableSsl="true"/>
</smtp>
</mailSettings>
</system.net>
I've already turn on the Less secure apps in my destination Google account.
What could be wrong here?

Getting error in sending email from Website hosted on Godaddy

I have hosted a website from Godaddy hosting in Windows ASP.net and have purchased an email also from there as well.
On that website, there is a ContactUs Page in which any visitor could fill in his details and Submit.
For this I am internally using my personal gmail id as 'From' and my info email ID as 'To' to send the email.
I am using the sample code they provided on their website as this link.
But I am getting this error:
An exception of type 'System.Net.Mail.SmtpException' occurred in System.dll but was not handled in user code.
Additional information: Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 72.167.234.197 (72.167.234.197:25), connect error 10060
On client.Send(message)
This is my web.config entry as per that link:
<system.net>
<mailSettings>
<smtp from="personalID#gmail.com">
<network host="relay-hosting.secureserver.net" port="25" />
</smtp>
</mailSettings>
</system.net>
And this is my code to send email:
StringBuilder body = new StringBuilder();
body.AppendLine("<h3>New Query Received:</h3>");
body.AppendLine();
body.AppendFormat("Name : {0}<br />", txtName.Text);
body.AppendFormat("Email : {0}<br />", txtEmail.Text);
body.AppendFormat("Phone : {0}<br />", txtMobile.Text);
body.AppendFormat("Query : {0}<br />", txtQuery.Text);
MailMessage message = new MailMessage();
message.From = new MailAddress("manish.rnsconsultancy#gmail.com");
message.To.Add(new MailAddress("info#rns-consultancy.com"));
message.Subject = "New Query from Website";
message.Body = body.ToString();
SmtpClient client = new SmtpClient();
client.Send(message);
Can anyone please help me in this matter, I am stuck on this as their customer support doesn't know other than that link.
I tried switching the emails as From and To also, but got the same error.
try this code to send email.
Send email using System.Net.Mail
To send mail using System.Net.Mail, you need to configure your SMTP service in your application's web.config file using these values for mailSettings:
<system.net>
<mailSettings>
<smtp from="your email address">
<network host="relay-hosting.secureserver.net" port="25" />
</smtp>
</mailSettings>
</system.net>
The network rule's value will be used when you instantiate an SmtpClient in your code.
PS: Please change port 3535 if you have problems with 25
C# code example
You can then use code similar to this to send email from your application:
MailMessage message = new MailMessage();
message.From = new MailAddress("your email address");
message.To.Add(new MailAddress("your recipient"));
message.Subject = "your subject";
message.Body = "content of your email";
SmtpClient client = new SmtpClient();
client.Send(message);
after checking you DNS record i found
smtp.asia.secureserver.net
Use this code and Add your password
var message = new MailMessage();
message.To.Add(new MailAddress("info#rns-consultancy.com"));
message.From = new MailAddress("info#rns-consultancy.com");
message.Subject = "Subject";
message.Body = "Body";
var smtpClient = new SmtpClient();
smtpClient.Host = "smtp.asia.secureserver.net";
smtpClient.Port = 25;
smtpClient.EnableSsl = false;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials =
new NetworkCredential("info#rns-consultancy.com", "Password");
//smtpClient.Port = 465;
//smtpClient.EnableSsl = true;
//smtpClient.Timeout = 10000;
// don't use 100000 in production it's 2 match
//, just for testing
smtpClient.Timeout = 100000;
smtpClient.Send(message);
refrences
Google Public DNS
Mail server addresses and ports for Business Email | Workspace Email - GoDaddy Help SG
Network Tools: DNS,IP,Email
Solved: Not able to send email via C#. - GoDaddy Community
What type of hosting account do I have? | GoDaddy Help AE
c# - SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission' - Stack Overflow

C# SmtpClient connecting to A2 hosting email

I am having a very hard time trying to send an email through an a2 hosting account. I know the code is correct as I have the same code sending emails through the Google SMTP. I was wondering if anyone had any experience or examples using a2 hosting email and SMTP c#. I've read through their documentation and it states to use user#hostingdomain.com for the username and then your password. For the server you can use the full domain name or the server name. For the port it says 587 or 465. I have tried a combination of all of these things and have not been able to connect. I keep getting this exception
"Unable to read data from the transport connection:
net_io_connectionclosed."
Thank you for any help.
Below is an example of the code I am using.
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("testuser#mydomain.a2hosted.com");
NetworkCredential myCred = new NetworkCredential(
"testuser#mydomain.a2hosted.com", "mypassword");
smtpClient.Host = "mydomain.a2hosted.com";
//smtpClient.Credentials = myCred;
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Credentials = myCred;
message.From = fromAddress;
message.Subject = "your subject";
//Set IsBodyHtml to true means you can send HTML email.
message.IsBodyHtml = true;
message.Body = "<h1>your message body</h1>";
message.To.Add("myemail#gmail.com");
smtpClient.Send(message);
All in here.
https://www.a2hosting.co.uk/kb/a2-hosting-products/windows-hosting/using-asp-net-to-send-e-mail-messages#C-example
Replace domain.a2hosted.com with your own domain name.
Replace user#example.com with the name of an e-mail account you created in Plesk.
Replace password with the password for the e-mail account you specified in the previous step.
From my config file.
<mailSettings>
<smtp from="noreply#goldendate.co.uk">
<network enableSsl="false"
defaultCredentials="false" host="yourdomain"
password="yourpassword" port="25"
userName="youremailaddress" />
</mailSettings>
If you work remotely, it'll not work.
You have to upload your code to a2hosting server and then it'll work.

Sending mail from gmail SMTP C# Connection Timeout

I have been trying to send an email via C# from a gmail account for account registration for my website.
I have tried several ways however the same exception continues to pop up: System.Net.Mail.Smtp Exception - Connection has timed out.
This is what I inluded in my Web.config file:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network"
from="Writely <mrbk.writely#gmail.com>">
<network host="smtp.gmail.com"
port="465"
enableSsl="true"
defaultCredentials="false"
userName="mrbk.writely#gmail.com"
password="******" />
</smtp>
</mailSettings>
</system.net>
where writely is the name of my website, and mrbk.writely#gmail.com is the account I wish to send an email from.
Then in my Account Controller when I connect with my database and save the user in my table, I am creating my MailMessage object and attempting to same the mail by:
using (DBConnection conn = new DBConnection())
{
conn.UserInfoes.Add(userInfo);
conn.SaveChanges();
MailMessage mail = new MailMessage();
mail.From = new MailAddress("mrbk.writely#gmail.com");
mail.To.Add("bernice.zerafa11#gmail.com");
mail.Subject = "Welcome to Writely";
mail.Body = "Test content";
SmtpClient smtp = new SmtpClient();
smtp.Send(mail);
}
Am I missing something or doing something wrong? I read that this is the good way to do this in some other question on stack overflow so I really don't know what's the problem here.
Thanks for your help :)
You need to tell the SmtpClient what settings to use. It does not automatically read this information from the Web.Config file.
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 465);
smtp.Credentials = new NetworkCredential("mrbk.writely#gmail.com", "***");
smtp.EnableSsl = true;
smtp.Send(mail);
gmail requires authentication:
Outgoing Mail (SMTP) Server
requires TLS or SSL: smtp.gmail.com (use authentication)
Use Authentication: Yes
Port for TLS/STARTTLS: 587
Port for SSL: 465
so what i did is
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("mrbk.writely#gmail.com", "mypwd"),
EnableSsl = true
};
client.Send("bernice.zerafa11#gmail.com", "bernice.zerafa11#gmail.com", "Welcome to Writely", "Test content");
I had the exact same problem and it's resolved after switching the port number from 465 to 587.
I had the problem on "email confirmation", "password recovery", and "sending email" and now all 3 problems are resolved :).
I know it's a pretty old post, but I usually use the existing posts to find answers instead of asking for new questions.
Thank you all for all your helps.
As I have already answered here.
This problem can also be caused by a security configuration in you gmail account.
The correct port is 587, but to authenticate you need to allow access from less secure apps in your gmail account.
Try it here
It worked for me, hope it helps..
Example in asp.net web forms/sharepoint
StringBuilder Body = new StringBuilder();
Body.Append("Your text");
String FromEmail = "you email";
String DisplayNameFromEmailMedico = "display when you receive email";
MailMessage message = new MailMessage();
message.From = new MailAddress(FromEmail, DisplayNameFromEmailMedico);
message.To.Add(new MailAddress("myclient#gmail.com"));
message.Subject = "subject that print in email";
message.IsBodyHtml = true;
message.Body = Body.ToString();
SmtpClient client = new SmtpClient();
NetworkCredential myCreds = new NetworkCredential("yoursmtpemail#gmail.com", "key from email smtp", "");
client.EnableSsl = true;
client.Credentials = myCreds;
client.Send(message);

SmtpClient .send() error: "message rejected as spam by content filtering"

Here is the code i wrote to send email,
MailMessage m = new MailMessage();
SmtpClient sc = new SmtpClient();
sc.UseDefaultCredentials = false;
try
{
m.From = new MailAddress(Sender);
m.To.Add(new MailAddress(Receiver));
m.Subject = Subject;
m.IsBodyHtml = true;
m.Body = Body;
sc.Send(m);
}
catch (Exception ex) { _Exceptions.ManageExceptions(ex); }
And the config file settings:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="xxx#xxx.com">
<network host="192.168.0.170" userName="setsdom01\user1" password="xxx" port="25" />
</smtp>
</mailSettings>
</system.net>
It executes when i run it from my machine, i try on different PC and it is giving me the following message: ...message rejected as spam by content filtering..
What could be the problem?
I think you need to add NetworkCredential backend code.
var AuthenticationDetails = new NetworkCredential("xxx#", "xxxx");
sc.Credentials = AuthenticationDetails;
This might work
Also look this How to Enable and Configure the Spam Confidence Level Thresholds may be helpful

Categories