Can't send mail to other mail-domain (only within same) - c#

I can only send mail within same mail-domain, but not outside it. Am I missing something?
try {
MailMessage mail = new MailMessage("noreply#company.com", "user#mail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.company.com";
mail.Subject = "Thanks...";
mail.Body = "text...";
client.Send(mail);
} catch (Exception ex) {
Response.Write(ex.ToString());
}
Error message when sending to other mail-domain:
System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The
server response was: 5.7.1 Unable to relay at
System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,
MailAddressCollection recipients, String deliveryNotify, Boolean
allowUnicode, SmtpFailedRecipientException& exception) at
System.Net.Mail.SmtpClient.Send(MailMessage message)
I've no control over the smtp host, but I should be able to send to other mail-domain.

Related

Mailing sending failing without proper details to debug further

I am using below code for sending email notification
private static void EMail() {
MailMessage message = new MailMessage();
message.From = new MailAddress(SourceEmail);
message.To.Add(Tolist);
message.CC.Add(CClist);
message.Subject = Subject;
message.IsBodyHtml = true;
message.Body = BODY;
using(SmtpClient smtpClient = new SmtpClient()) {
smtpClient.EnableSsl => true;
smtpClient.UseDefaultCredentials = false;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
smtpClient.Credentials = (ICredentialsByHost) new NetworkCredential(U_Name, PWD);
smtpClient.Host = Host;
smtpClient.Port = Port;
smtpClient.DeliveryMehod = SmtpDeliveryMethod.Network;
smtpClient.Send(message);
Environment.Exit(0);
}
}
But it was failing with below error, Please help me here
Information: Error while Sending Email     at
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode,
String response) at System.Net.Mail.MailCommand.Send(SmtpConnection
conn, Byte[] command, MailAddress from, Boolean allowUnicode)your
text at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender,
MailAddressCollection recipients, String deliveryNotify, Boolean
allowUnicode, SmtpFailedRecipientException& exception) at
System.Net.Mail.SmtpClient.Send(MailMessage message) at
Program.EMail() at Program.Main(String[] args)
I would expect to send email or show some valid error to debug further

unable to connect to the remote server c# - godaddy

I am trying to send mail from Web API using SMTP (GODaddy). It failed to send the mail and returning the exception as follows
Code :
public void SendMail()
{
try
{
MailMessage mail = new MailMessage("support#abc.com","toMail");
mail.Subject = "Subject";
mail.IsBodyHtml = true;
mail.Body = "this is email body";
SmtpClient client = new SmtpClient("relay-hosting.secureserver.net");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("support#abc.com", "****");
client.Port = 25;
client.Send(mail);
}
catch (SmtpFailedRecipientException Ex)
{
Ex.FailedRecipient.ToString();
}
}
Can anyone help me to fix this.

The server response was: 5.7.0 Too many messages in too short a time frame at System.Net.Mail.SmtpTransport

I am developing one Windows Application sending bulk mails.
It worked successfully for 100 mails. After that it starts showing
these errors
The server response was: 5.7.0 Too many messages in too short a time frame at
System.Net.Mail.SmtpTransport.SendMail(
MailAddress sender,
MailAddressCollection recipients,
String deliveryNotify,
Boolean allowUnicode,
SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at SmsAndEmail.Email.EmailIndex.SendTheMail()
This is my code:
MailMessage msg = new MailMessage();
msg.From = new MailAddress("MailAddress");
msg.To.Add(mail.ToAddress);
msg.Subject = "MySub";
msg.Body = mail.EmailBody;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = true;
client.Host = "hostname";
client.Port = 587;
client.EnableSsl = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential("MailAddress", "password");
client.Timeout = 20000;
ServicePointManager.ServerCertificateValidationCallback =
delegate(
object s,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors
)
{ return true; }
;
try
{
client.Send(msg);
newStatus = "SUCCESS";
}
catch (Exception ex)
{
newStatus = "Failed";
errorMessage = "Mail Sending Failed !";
return errorMessage;
}

Emailing from Gmail error on DisplayName property

Bellow is my code when i remove DisplayName Property of MailAddress() it work fine but Receiving end mail show EmailID on Display Name like emailID#gmail.com.
MailMessage mail = new MailMessage();
mail.From = new System.Net.Mail.MailAddress("emailID#domainName.com");
// The important part -- configuring the SMTP client
SmtpClient smtp = new SmtpClient();
smtp.Port = 587; // [1] You can try with 465 also, I always used 587 and got success
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
smtp.UseDefaultCredentials = false; // [3] Changed this
smtp.Credentials = new NetworkCredential(mail.From.ToString(), "password"); // [4] Added this. Note, first parameter is NOT string.
smtp.Host = "smtp.gmail.com";
mail.IsBodyHtml = true;
mail.Subject = Subject;
mail.Body = Body;
mail.To.Add(new MailAddress(To));
smtp.Send(mail);
mail.Dispose();
When i add Display name of MailAddress() i receive this error message.
System.Net.Mail.SmtpException: 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 at
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode,
String response) at System.Net.Mail.SmtpTransport.SendMail(MailAddress
sender, MailAddressCollection recipients, String deliveryNotify,
Boolean allowUnicode, SmtpFailedRecipientException& exception) at
System.Net.Mail.SmtpClient.Send(MailMessage message) at ***
Where i am wrong?
var client = new SmtpClient
{
Host = "smtp.googlemail.com",
Port = 587,
UseDefaultCredentials = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
EnableSsl = true,
Credentials = new NetworkCredential(SmtpUserName, SmtpUserPassword);
};
client.Send(mail);
where mail is an instance of MailMessage
private static SecureString _smtpPassword;
public static SecureString SmtpUserPassword
{
get
{
if (_smtpPassword != null)
return _smtpPassword;
_smtpPassword = new SecureString();
foreach (var c in "your password here")
_smtpPassword.AppendChar(c);
_smtpPassword.MakeReadOnly();
return _smtpPassword;
}
}

SmtpException was caught when sending mail

my code:
private void button1_Click(object sender, EventArgs e)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("mymail#gmail.com", "mypassword");
client.EnableSsl = true;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("mymail#gmail.com", "SMTP Test");
mail.To.Add(new MailAddress("mymail#gmail.com"));
mail.Subject = "Subject test";
mail.Body = "Body test";
client.Send(mail);
MessageBox.Show("mail send.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I get this error:
I cant upload images yet so i use puush.
http://puu.sh/fpAnF/d4372b0b55.png
Error a bit translated:
Error when sending e-mail. system.net.mail.smtpexception: error when
sending e-mail. ---> system.net.webexception: can't connect to the
external server ---> system.net.sockets.sochetexception: can't connect
because the goalcomputer (dont know the exact translation of that) the
connection actively has refused.
can somobody please help me?

Categories

Resources