Sending an email using System.Net.Mail or System.Web.Mail

S

sanjeev

I am attempting to send an email from a C# app and get the following
error -

[System.Web.HttpException] = {"The server rejected one or more
recipient addresses. The server response was: 554 Relay rejected for
policy reasons.\r\n"}

I can only send emails to addresses within my domain. What do I have to
do in order to ensure that the mail server allows the emails to outside
addresses. I have attempted using classes from System.Net.Mail and
System.Web.Mail and get the same error if sending mail outside my
domain.

Here is a code snippet (I have edited the username/pwd) -

--------------------------------------------------------------------------------------------------------------------
System.Web.Mail.MailMessage mail = new
System.Web.Mail.MailMessage();

mail.From = "(e-mail address removed)";
mail.To = "(e-mail address removed)";

mail.Subject = "This is an email";
mail.Body = "The tulips are blooming!";



try
{
//to authenticate we set the username and password
properites on the SmtpClient
// SmtpClient smtp = new SmtpClient("192.168.1.7");
//smtp.Credentials = new NetworkCredential("username",
"pwd");
//smtp.Send(mail);


System.Web.Mail.SmtpMail.SmtpServer = "192.168.1.7";
System.Web.Mail.SmtpMail.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
 
C

Christopher Reed

You have to talk to your mail administrator to allow for relaying of emails
from your web server.
 
G

Guest

Hello,

Maybe you need to authenticate in order to send the e-mail (to avoid
spammers if you access to a remote e-mail server you need to authenticate
yourself).

Some heplful links, if you use VStudio 2003 (.net framework 1.1)

http://www.systemwebmail.com/allfaq.aspx

If you are using VStudio 2005 (.net framework 2.0)

http://www.systemnetmail.com/

Good luck
Braulio



--
/// ------------------------------
/// Braulio Díez Colaborador DNM
///
/// http://www.dotnetmania.com
/// My Site (.net Tips): http://www.bdiez.com
/// ------------------------------
 
S

sanjeev

Thanks, I will follow up with for your suggestions.

Sanjeev


Braulio said:
Hello,

Maybe you need to authenticate in order to send the e-mail (to avoid
spammers if you access to a remote e-mail server you need to authenticate
yourself).

Some heplful links, if you use VStudio 2003 (.net framework 1.1)

http://www.systemwebmail.com/allfaq.aspx

If you are using VStudio 2005 (.net framework 2.0)

http://www.systemnetmail.com/

Good luck
Braulio



--
/// ------------------------------
/// Braulio Díez Colaborador DNM
///
/// http://www.dotnetmania.com
/// My Site (.net Tips): http://www.bdiez.com
/// ------------------------------




I am attempting to send an email from a C# app and get the following
error -

[System.Web.HttpException] = {"The server rejected one or more
recipient addresses. The server response was: 554 Relay rejected for
policy reasons.\r\n"}

I can only send emails to addresses within my domain. What do I have to
do in order to ensure that the mail server allows the emails to outside
addresses. I have attempted using classes from System.Net.Mail and
System.Web.Mail and get the same error if sending mail outside my
domain.

Here is a code snippet (I have edited the username/pwd) -

--------------------------------------------------------------------------------------------------------------------
System.Web.Mail.MailMessage mail = new
System.Web.Mail.MailMessage();

mail.From = "(e-mail address removed)";
mail.To = "(e-mail address removed)";

mail.Subject = "This is an email";
mail.Body = "The tulips are blooming!";



try
{
//to authenticate we set the username and password
properites on the SmtpClient
// SmtpClient smtp = new SmtpClient("192.168.1.7");
//smtp.Credentials = new NetworkCredential("username",
"pwd");
//smtp.Send(mail);


System.Web.Mail.SmtpMail.SmtpServer = "192.168.1.7";
System.Web.Mail.SmtpMail.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

--------------------------------------------------------------------------------------------------------------------

Regards,

Sanjeev.
 
S

sanjeev

Thanks for the suggestions - the FAQ at System.Net.Mail is certainly
useful. Also, after speaking with the Sys Admin we discovered that the
Domino mail server is currently set to stop outgoing mail from any
client other than Lotus Notes. To test the proof of concept I am simply
using a gmail server.

Sanjeev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top