Trying to send an email

J

John Straumann

Hi all:

I am trying to write some code to send an email from an Assembly file, and
found some examples on MSDN. However when I run the program (I am using a
console app for testing), the email does not send. I do not get an error,
but nothing gets sent. The code is pasted below, any and all help is greatly
appreciated.

I have changed the "to" address and the password for "no spam" reasons. :)

Thanks.

John.

static void Main(string[] args)
{
try
{

//MailMessage theMailMessage = new
MailMessage("(e-mail address removed)", "(e-mail address removed)");
MailMessage theMailMessage = new MailMessage();
theMailMessage.From = new MailAddress( "(e-mail address removed)" );
theMailMessage.To.Add( "(e-mail address removed)" );
theMailMessage.Subject = "This is an email";
theMailMessage.Body = "body email message here";

SmtpClient theClient = new SmtpClient("192.168.1.77", 25);
theClient.UseDefaultCredentials = false;
System.Net.NetworkCredential theCredential = new
System.Net.NetworkCredential("(e-mail address removed)", "******");
theClient.Credentials = theCredential;
theClient.Send(theMailMessage);

}
catch (Exception ex)
{
Console.WriteLine(" Error " + ex.ToString());
}
 
A

Arne Vajhøj

John said:
I am trying to write some code to send an email from an Assembly file,
and found some examples on MSDN. However when I run the program (I am
using a console app for testing), the email does not send. I do not get
an error, but nothing gets sent. The code is pasted below, any and all
help is greatly appreciated.

No exception could mean that the email got send but just ended
up in the spam filter.

Arne
 
L

Liz

John Straumann said:
Hi all:

I am trying to write some code to send an email from an Assembly file, and
found some examples on MSDN. However when I run the program (I am using a
console app for testing), the email does not send. I do not get an error,
but nothing gets sent. The code is pasted below, any and all help is
greatly appreciated.


worked for me; can you look at the mail server logs? are you sure you need
authentication on the server? can you use localhost as your server, at least
to get the code working? or is that address already your dev machine?

I have changed the "to" address and the password for "no spam" reasons. :)

Thanks.

John.

static void Main(string[] args)
{
try
{

//MailMessage theMailMessage = new
MailMessage("(e-mail address removed)", "(e-mail address removed)");
MailMessage theMailMessage = new MailMessage();
theMailMessage.From = new MailAddress( "(e-mail address removed)" );
theMailMessage.To.Add( "(e-mail address removed)" );
theMailMessage.Subject = "This is an email";
theMailMessage.Body = "body email message here";

SmtpClient theClient = new SmtpClient("192.168.1.77", 25);
theClient.UseDefaultCredentials = false;
System.Net.NetworkCredential theCredential = new
System.Net.NetworkCredential("(e-mail address removed)", "******");
theClient.Credentials = theCredential;
theClient.Send(theMailMessage);

}
catch (Exception ex)
{
Console.WriteLine(" Error " + ex.ToString());
}
 
J

Jon Skeet [C# MVP]

Or simple that port 25 is closed in your viruschecker

If it weren't able to connect to the mail server, wouldn't that show as
an exception? I'd certainly expect it to.
 
J

John Straumann

Hi all:

Thanks for all the replies, I am not sure what the issue could be. I opened
Outlook to try to send some messages, and I can send messages to myself on
the server, but when I tried to send an outgoing message to Hotmail or
another outbound address it fails. In Outlook I get a "Delivery Status
Notification (Delay)" message.

I tried to check to be sure port 25 is not blocked by Windows firewall on
the server but as far as I can tell the firewall is not running. Gotta keep
looking but the issue doesn't seem to be the Csharp code.

John.


Liz said:
John Straumann said:
Hi all:

I am trying to write some code to send an email from an Assembly file,
and found some examples on MSDN. However when I run the program (I am
using a console app for testing), the email does not send. I do not get
an error, but nothing gets sent. The code is pasted below, any and all
help is greatly appreciated.


worked for me; can you look at the mail server logs? are you sure you
need authentication on the server? can you use localhost as your server,
at least to get the code working? or is that address already your dev
machine?

I have changed the "to" address and the password for "no spam" reasons.
:)

Thanks.

John.

static void Main(string[] args)
{
try
{

//MailMessage theMailMessage = new
MailMessage("(e-mail address removed)", "(e-mail address removed)");
MailMessage theMailMessage = new MailMessage();
theMailMessage.From = new MailAddress( "(e-mail address removed)" );
theMailMessage.To.Add( "(e-mail address removed)" );
theMailMessage.Subject = "This is an email";
theMailMessage.Body = "body email message here";

SmtpClient theClient = new SmtpClient("192.168.1.77", 25);
theClient.UseDefaultCredentials = false;
System.Net.NetworkCredential theCredential = new
System.Net.NetworkCredential("(e-mail address removed)", "******");
theClient.Credentials = theCredential;
theClient.Send(theMailMessage);

}
catch (Exception ex)
{
Console.WriteLine(" Error " + ex.ToString());
}
 
N

Nicholas Paldino [.NET/C# MVP]

Well, the OP doesn't specify that he can't connect to the mail server,
he just says that the email doesn't send. He doesn't specify what his
definition of "doesn't send" or how he is gauging that fact (if I was
waiting on the other side for the email to come in, I wouldn't say that the
email is never sent but rather never received). Regardless, without
clarification from the OP, it's ambiguous at best.
 
J

Jon Skeet [C# MVP]

Nicholas Paldino said:
Well, the OP doesn't specify that he can't connect to the mail server,
he just says that the email doesn't send. He doesn't specify what his
definition of "doesn't send" or how he is gauging that fact (if I was
waiting on the other side for the email to come in, I wouldn't say that the
email is never sent but rather never received). Regardless, without
clarification from the OP, it's ambiguous at best.

Well, he did imply that no exception was thrown: "I do not get
an error, but nothing gets sent".

I would certainly *hope* that if the mail server couldn't be contacted,
the OP would receive an error.
 

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

Similar Threads

SMTP failure 1
problem in Sending email in c# 1
C# - Email problems 2
Failure to Send email 1
System.Net.Mail and SSL 1
Send Email in ASP.net 4
Email... HELP 1
Email sent to deleted items 4

Top