Mailbox unavailable. The server response was: 5.7.54 SMTP - c#

We are trying to send mail through SMTP setup as below
SmtpClient smtpClient = new SmtpClient(SMTPServer, SMTPPort);
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new NetworkCredential(SMTPUserName, SMTPassword);
MailAddress mailAddress = null;
if (!string.IsNullOrEmpty(sFromEmail))
mailAddress = new MailAddress(sFromEmail);
else
mailAddress = new MailAddress(SMTPEmailID);
MailMessage mailMessage = new MailMessage();
mailMessage.From = mailAddress;
mailMessage.Subject = sEmailSubject;
foreach (string toAddress in sToEmail.Split(';'))
{
if (toAddress.Trim() != string.Empty)
mailMessage.To.Add(toAddress);
}
mailMessage.IsBodyHtml = true;
mailMessage.Body = sEmailBody;
smtpClient.Send(mailMessage);
logText.Add(Environment.NewLine);
logText.Add("Mail sent successfully at " + DateTime.Now.ToString());
logCreation.createLogFileFromList(logText);
logText.Clear();
sErrorMessage = "Mail sent successfully";
but this end up with error
Mailbox unavailable. The server response was: 5.7.54 SMTP; Unable to
relay recipient in non-accepted domain
any setup I am missing here..

First
Email gateway is a SMTP server in charge of filter virus or spam. Email Gateway user maybe included spam list check this
Second
If you change your mail server ip address,your domain system may not have generalization dns in your exchange system.
Third
If you change your mail server ip address,your domain system may not have generalization your exchange system. You must be force generelization dns.
At this point can you check your project in running server
open powershell and edit your email info then run this query
send-mailmessage -to '<test#test.com>' -From '<admin#test.com>' -subject "TEST" -body "hi" -smtpServer mail.yourlocalsmtpdns.com
if you take this error change mail.yourlocalsmtpdns.com to your smtp ip address
if you not take error. You can think that your problem cause smtp domain address.
Fast solution,
you can connect to smtp with smtp ip address to your project.

Related

Mailbox unavailable. The server response was: sorry, no mailbox here by that name (#5.1.1)

Hi I am developing web application in mvc5. I have email notifications to send it to our customers. I am using below details to send emails. I have hosted application with ssl mode. Port is 25, smtpServer is mail.ourdomain.com and email is alert#ourdomain.com. We use below code to send emails.
string AdminEmail = ConfigurationManager.AppSettings["AdminEmail"].ToString();
MailMessage mail = new MailMessage();
mail.To.Add(emailid);
mail.Bcc.Add(AdminEmail);
mail.From = new MailAddress(MailID);
mail.Subject = Subject;
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient(hostserver);
smtp.Credentials = new System.Net.NetworkCredential(MailID, Password);
smtp.Send(mail);
I found in the error log and there is Mailbox unavailable. The server response was: sorry, no mailbox here by that name (#5.1.1) May i know the root cause of this problem. Any help would be appreciated. Thank you.
This is because you have not created the object of MailAddress correctly.
Please see below way of creating mail address:
Message = new MailMessage();
Message.From = new MailAddress(UseremailId, "Your Application");
this will resolve the above issue.

Failed to send an EMail with body contains ip address and port no

I have create function to send an email. This function was work successful on localhost but on server its failed without any exception. I know the problem comes from my Port on IP Address.
The sample body is string body = "<p>Please click here</p>Thank You."
The problem is : between IP Address and Port.
Successful send an email if i remove :.
Do you guys have any ideas?
public void Sent(string sender, string receiver, string subject, string body)
{
using (MailMessage mail = new MailMessage(sender, receiver))
{
using (SmtpClient client = new SmtpClient())
{
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "mail.companyName.com.my";
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = body;
client.Send(mail);
}
}
}
You are doing it right, the code to send the mail is ok (you may want to revise the function name and make the smtp host name configurable, but that is not the point here).
The e-mail delivery fails on a relay, there is no immedieate feedback (no exception) to the client about this kind of failure.
The best bet is the IncreaseScoreWithRedirectToOtherPort property set in Set-HostedContentFilterPolicy in case your mail provider is Office365, or a similar spam filter mechanism in any other mail provider that is encountered down the mail delivery chain.
You can set a reply-to address and hope that the destination server will bounce a delivery failure that gives you more information. Or have the admin of the mail server look up the logs. More information here:
https://serverfault.com/questions/659861/office-365-exchange-online-any-way-to-block-false-url-spam
Try setting the 'mail.Body' to receive a Raw Html message instead of a encoded string, like:
mail.Body = new System.Web.Mvc.HtmlHelper(new System.Web.Mvc.ViewContext(), new System.Web.Mvc.ViewPage()).Raw(body).ToString();
Or put a using System.Web.Mvc at the beginning so it gets shorter and easier to understand:
using System.Web.Mvc
mail.Body = new HtmlHelper(new ViewContext(), new ViewPage()).Raw(body).ToString();

Can i use IP Address as SMTP host rather then smtp.email.com

i am creating an Email sending sample application, and i want to use send email from different email address like "gmail, yahoo, hotmail" so i don't want to use "smtp.email.com" as host, because if i use "smtp.email.com" as host i will have to change my host name for every different company like("smtp.gmail.com" for gmail or "smtp.mail.yahoo.com" for yahoo.com ) so
Can i use IP Address as SMTP host rather then smtp.email.com.
Please give me a solution for this so that without changing smtp host name i can use different email company to send email.
this is my code:
try
{
// setup mail message
MailMessage message = new MailMessage();
message.From = new MailAddress(textBox1.Text);
message.To.Add(new MailAddress(textBox2.Text));
message.Subject = textBox3.Text;
message.Body = richTextBox1.Text;
// setup mail client
SmtpClient mailClient = new SmtpClient("smtp.gmail.com");//here i have to change SMTP host for different email company
mailClient.Credentials = new NetworkCredential(textBox1.Text,"password");
// send message
mailClient.Send(message);
MessageBox.Show("Sent");
}
catch(Exception)
{
MessageBox.Show("Error");
}
Sure you could use IP addresses instead of names, but remember then if they ever changed the IP you're goning to stop working.. BUT.... this needs to change depending on what you are sending the mail as unless you find some form of relay proxy thats open.. AS yahoo wont recveive gmail and gmail wont receive yahoo etc.. The reality is if you are sending as that it would end up changing wether you used an IP or a name.
Your webserver however will most likely send mails from your domain, rather than your gmail/yahoo accounts.. why not send it from your domain? eg noreply#myweb.com then the smtp server remains the same as its your web provider
Of course you could do
SmtpClient mailClient
if (textbox1.Text.Contains("gmail")
{
mailClient = new SmtpClient("smtp.gmail.com");/
mailClient.Credentials = new NetworkCredential(textBox1.Text,"password");
}
else if (textbox1.Text.Contains("somemail")
{
mailClient = new SmtpClient("smtp.somemail.com");/
mailClient.Credentials = new NetworkCredential(textBox1.Text,"password");
}
etc

Send mail works locally but not on server?

This code works locally, but when I upload it to my server on Godaddy, it does not send the e-mail. Any idea why it doesn't work on their server? What do I need to change?
try {
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("Myemail#gmail.com");
mail.To.Add("Myemail#gmail.com");
mail.Subject = "New sign up";
mail.Body = "New member";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("Myemail#gmail.com", "**Mypass**");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
} catch(Exception ex) {
throw ex;
}
They may be blocking outgoing SMTP connections in order to prevent spammers from using their service to send spam. You should check what error messages you're getting and check your server host's policy.
There are a couple of things you need to do when sending from inside a site hosted from Godaddy. Use their relay server to send the message (this won't work from your dev machine, you'll have to test it live after you upload it). Here is the relay server info. Also make sure the "from" address is an email within the same domain. I usually use the same as the toAddress. See here for info on why this is necessary.
This is the code I'm using to send from a site inside Godaddy:
btnSend.Disabled = true;
const string serverHost = "relay-hosting.secureserver.net";
var msg = new MailMessage(toAddress, toAddress);
msg.ReplyTo = new MailAddress(emailFrom);
msg.Subject = subject;
msg.Body = emailBody;
msg.IsBodyHtml = false;
try
{
var smtp = new SmtpClient();
smtp.Host = serverHost;
smtp.Credentials = new System.Net.NetworkCredential("account", "password");
smtp.Send(msg);
}
catch (Exception e)
{
//Log the errors so that we can see them somewhere
}
You need to send your email via the godaddy smtp servers. I experienced the same issue with them before I think. I believe they give instructions of how to login via their FAQ.
If you have ssh access to the server, try to telnet smtp.google.com via 25 and 465 ports also. If you get a timeout, then you're likely firewalled from connecting to these ports outside a certain IP range.
Port 587 is for TLS. As you're using SSL, try port 465.

SMTP Mail Sending

I am using following code to send email:
MailMessage Mailer = new MailMessage();
Mailer.From = new MailAddress(From);
Mailer.To.Add(new MailAddress(To));
Mailer.Subject = Subject;
Mailer.Body = Body;
Mailer.IsBodyHtml = isBodyHTML;
SmtpClient mSmtpClient = new SmtpClient();
mSmtpClient.Host = "ExchangeServer.XXX.YYY.COM"; // Our Exchange server Name
Mailer.Attachments.Add(new System.Net.Mail.Attachment(strLogFile));
mSmtpClient.Send(Mailer);
I stopped my SMTP service but still mail was sent sucessfully. I just want to understand if my SMTP service is stopped how could program send email, shouldn't it be dumped in the mailroot folder?
Thanks,
Praveen
Looks like you've told it to use the exchange server with this line here:
mSmtpClient.Host = "ExchangeServer.XXX.YYY.COM"; // Our Exchange server Name
So it won't use your smtp service at all. Change that line of code to this:
mSmtpClient.Host = "localhost";
It will start using the local smtp service, and will fail if you try to run the code with the service stopped.

Categories

Resources