I want to send email with my web application. It is published on rackspace dedicated server but I'm using GoDaddy's SMTP server to send email.
The fault I'm getting is:
System.Net.Mail.SmtpFailedRecipientException: Mailbox name not allowed. The server response was: sorry, relaying denied from your location [xx.xx.xxx.xx] (#5.7.1)
This is my code
SmtpClient client = new SmtpClient("relay-hosting.secureserver.net", 25);
string to ="rpanchal#itaxsmart.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new System.Net.NetworkCredential("EmailId#domain.com","**");
MailAddress fromAddress = new MailAddress("myEmailId#domain.com", "CompanyName");
MailMessage message = new MailMessage();
message.From = fromAddress;
message.To.Add(to);
message.Body = "This is Test message";
message.Subject = "hi";
client.Send(message); message.Dispose(); return "Email Send";
Should I do any configuration on dedicated server?
Are you testing locally? If yes, then your SMTP server may not allow relaying. Do not worry when you will deploy the application there won't be any problem.
If you are hosting with RackSpace you should use the SMTP RackSpace recommends for sending from their servers. Unfortunately, you can only use relay-hosting.secureserver.net if you are sending from go Daddy Shared or 4GH hosting.
Start trying to change your port 465 instead 25.
Or remember Relay-hosting is very limited to 250 emails per day and not accept remote connections so easy. Check if you can use SSL connection.
That is so simple:
You must focus on smtp host, port, ssl...
Change smtp host to: relay-hosting.secureserver.net
And DELETE port and ssl, thats all...
Do not use smtp port and smtp ssl true or false
var fromAddress = "mailfrom#yourdomain";
// any address where the email will be sending
var toAddress = "mailto#yourdomain";
//Password of your mail address
const string fromPassword = "******";
// Passing the values and make a email formate to display
string subject = TextBox1.Text.ToString();
string body = "From: " + TextBox2.Text + "\n";
body += "Email: " + TextBox3.Text + "\n";
body += "Subject: " + TextBox4.Text + "\n";
body += "Message: \n" + TextBox5.Text + "\n";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "relay-hosting.secureserver.net";
**//Warning Delete =>//smtp.Port = 80;**
**//Warning Delete =>//smtp.EnableSsl = false;**
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
Related
Good day, I'm a beginner from using ASP.net and SMTP Mailer
Heres my Question, I always encounter this Error when i send email from my local
and searched and tried the solutions around the net but not so lucky,
I hope someone point out what codes do i need and where i encounter this errror
Message = "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at"
Heres my Code:
protected void btnSendEmail_Click(object sender, EventArgs e)
{
// System.Web.Mail.SmtpMail.SmtpServer is obsolete in 2.0
// System.Net.Mail.SmtpClient is the alternate class for this in 2.0
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress(txtEmail.Value, txtName.Value);
smtpClient.Credentials = new System.Net.NetworkCredential("myUser#gmail", "password");
// You can specify the host name or ipaddress of your server
// Default in IIS will be localhost
smtpClient.Host = "smtp.gmail.com";
smtpClient.EnableSsl = true;
//Default port will be 25
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = false;
//From address will be given as a MailAddress Object
message.From = fromAddress;
// To address collection of MailAddress
message.To.Add("myEmail#gmail.com");
message.Subject = txtSubject.Value;
// CC and BCC optional
// MailAddressCollection class is used to send the email to various users
// You can specify Address as new MailAddress("admin1#yoursite.com")
message.CC.Add("myEmail#gmail.com");
// You can specify Address directly as string
message.Bcc.Add(new MailAddress("myEmail#gmail.com"));
//Body can be Html or text format
//Specify true if it is html message
message.IsBodyHtml = false;
// Message body content
message.Body = txtaMessage.Value;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.HeadersEncoding = System.Text.Encoding.UTF8;
// Send SMTP mail
smtpClient.Send(message);
lblSuccess.Text = "Email successfully sent.";
}
catch (Exception ex)
{
lblSuccess.Text = "Send Email Failed.";
}
}
i tried to make a simple codes for sending email try this
MailMessage mm = new MailMessage();
mm.From = new MailAddress("fromEmail");
mm.To.Add("toEmail");
mm.CC.Add("ccEmail");
mm.Subject = "StringSubject";
mm.Body = "BodySubject";
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "UsernameString";
NetworkCred.Password = "PasswordString";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
try
{
smtp.Send(mm);
}
catch (Exception)
{
}
Try this reference ASP Simple SMTP for C# and VB it helps me a lot for may smtp problem
Please have a look on google support team, what they are saying regarding sending mail from application.
https://support.google.com/mail/answer/78775?hl=en
Also following link can help you.
Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
Goto Account of Gmail , then select
Connected apps & sites
Allow less secure apps: ON(if this is off you cannot send mails through apps,or your websites )
I have deployed my website to azure cloud and I am trying to send emails to my client. When I have tested this on local host it works properly but on moving to cloud it shows several errors like sometimes:
-> connection time out and i have declared timeout as 150000
->The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. (I have made less secure app allowed to mail account)
Here I am attaching my code. Please review it and suggest a way to resolve it.
Thank you all in advance.
protected void Button2_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
MailAddress from = new MailAddress("bvpcsccloud#gmail.com");
MailAddress to = new MailAddress(Label7.Text);
string subjectText = "E-appointment request";
string bodyText = #"Hi, This mail is for the request of e-appointment from our patient:"+TextBox4.Text.ToString()+"<br />"+ "The patient has age:";
bodyText += TextBox5.Text.ToString()+"<br /> Disease symbols are"+TextBox2.Text.ToString()+"<br /> Disease name:"+ TextBox3.Text.ToString();
bodyText += "<br />Patient address is" + TextBox1.Text.ToString();
bodyText += "<br /> preffered date choosen by patient is" + DropDownList1.SelectedItem.Text + "-" + DropDownList2.SelectedItem.ToString() + "-" + DropDownList3.SelectedItem.Text;
msg.To.Add(to);
msg.From = from;
msg.Subject = subjectText;
msg.Body = bodyText;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
//smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential("bvpcsccloud#gmail.com", "password");
//smtp.UseDefaultCredentials = false;
try
{
smtp.EnableSsl = true;
smtp.Timeout = 150000;
smtp.Send(msg);
smtp.Dispose();
Response.Redirect("~/appointment_booked.aspx");
}
catch (Exception ex)
{
throw ex;
}
}
I am trying to send a default passwords using smtp for users who want to retrieve their new passwords!
My Code :
public void SendUserPass()
{
string sql = "Select Username, Password from Registration
where Email='" + Email + "'";
DataTable table = new DataTable();
table = db.RunQuery(sql);
MailMessage message = new MailMessage("Esco#gmail.com", Email);
message.Subject = "ESCO -Forgot Password";
message.Body = "Username " + table.Rows[0][0].ToString() + "<br/> Password" +
table.Rows[0][1].ToString();
message.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("Esco#gmail.com", "Mypassword");
smtp.EnableSsl = true;
smtp.Send(message);
}
I get this error :
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at....
Line 310: smtp.Send(message);
Any help please ?
This worked for me
Login in to gmail ( in your case it is Esco#gmail.com)
visit
https://www.google.com/settings/security/lesssecureapps
Enable access to less secure apps
I have the following code which if I send an mail its showing email ending fail how to solve this one?
public void Sendemail(string toaddr)
{
if (Editor1.Content == null)
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Subject or Body of Email Should not be Empty...!');", true);
}
else
{
string[] arryaddr = toaddr.Split(',');
MailMessage ms = new MailMessage();
ms.IsBodyHtml = true;
//ms.To.Add(new MailAddress("admin#digitalprintonline.co.uk"));
ms.To.Add(new MailAddress(toaddr));
string fromaddr = "admin#digitalprintonline.co.uk";
for (int i = 0; i < arryaddr.Length; i++)
{
ms.Bcc.Add(new MailAddress(arryaddr[i].ToString()));
}
ms.From = new MailAddress(fromaddr);
string subject = txtSubject.Text;
ms.Subject = subject;
string body = Editor1.Content;
ms.Body = body;
ms.Priority = MailPriority.Normal;
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new System.Net.NetworkCredential("admin#digitalprintonline.co.uk", "dpo123");
try
{
smtp.Send(ms);
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Email Sent Successfully...!');", true);
}
catch (Exception ex)
{
}
}
}
I have the following email settings
smtp from="admin#dpoweddings.co.uk"
network host="217.199.175.121"
port="25"
userName="admin#digitalprintonline.co.uk"
password="*****"
enableSsl="false"
SMTPClient uses SMTP (protocol) to send emails. Thus it requires the details about the SMTP Server. Consider the code below
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("username#gmail.com", "password");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
In the above code, we have provided the following information to the SMTP client to work properly
Host: The smtp server details. As you can see, by default you use #gmail.com but here it is specified smtp.gmail.com
Port: The port to connect to the smtp server
EnableSsl: If ssl connection is required
Credentials: The account using whose credentials the mail should be sent.
Your code is missing the Host and Port (which are also required along with Credentials, EnableSsl is false, by default)
To know about details (host, port, Ssl requirement) of SMTP server at digitalprintonline.co.uk, you will have to contact the administrator there. Alternatively, you can use GMail SMTP server details along with your GMail account credentials.
You don't need to have a server on your local machine in order to send a message to a SmtpClient. Your email service provider such as smtp.gmail.com has the server and your SmtpClient communicates with that server.
I am attending to send email via the following function and while it works fine when I run it from the local server, it fails when I run it remotely. What might be causing this problem?
private void SendEmail()
{
try
{
MailMessage message = new MailMessage();
SmtpClient client = new SmtpClient("smtp.gmail.com",587);
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
NetworkCredential loginInfo = new NetworkCredential("xx#gmail.com", "xxxx");
message.From = new MailAddress("xx#gmail.com", "xx");
message.To.Add(new MailAddress("yyy#zzz.ac.in","Mail"));
message.IsBodyHtml = true ;
string emailContent = "ICHE 2010 - Abstract Received <br><br>Title: " + Abstract_Title.Text + "<br><br>Author: " + TxtAuthor_FirstName.Text + "_" + TxtAuthor_LastName.Text + "<br><br>Abstract in pdf format attached with this email. <br><br> ICHE2010 Website";
message.Body = emailContent;
message.Subject = "ICHE 2010 - Abstract Received";
string FileName = Server.MapPath(Request.ApplicationPath + "\\AbstractPdfs" + "\\" + abstractBO.AbstractFileNameWithTicks);
Attachment attachmentpdf = new System.Net.Mail.Attachment(FileName);
message.Attachments.Add(attachmentpdf);
client.EnableSsl = true;
client.Send(message);
}
catch (SmtpException smtpex)
{
throw smtpex;
}
catch (Exception ex)
{
throw ex;
}
}
May be the firewall is blocking your application from sending email using the port. Or your remote server may not have internet connection. There can be many reasons for this. Please explain more.
You need to check two things:
From your code, check to see if port 587 is not blocked, or is enabled
Also try opening port 25, which is the port traditionally used by SMTP