System.Net.Mail.SmtpClient MailClient message. How do u know if it was successful?

C

Claire

I'm a noob at emailing from code and I need to add email capabilities to my
application.
The following code completes without exceptions but I'm not receiving any
test emails.
How do you debug this? Ive checked my bad mail folder, and other IIS similar
folders and they're empty.
Can the mail classes be used without having a SMTP server running on
localhost? Can you use any smtp server that's capable of being set up from a
PC, e.g. an ISP account?
If so, do you need to obtain the settings that you might find in an outlook
express email server tab?
Does the MailClient accept all the possible settings via properties?
Are there any recommended freeware/opensource SMTP server .net controls out
there that I could plug into my application so I don't have to require the
user to do any configuration?

thank you
Claire

public void SendEmail(string Sender, string Recipient, string Subject,
string Body)
{
string fnName = "SendEmail";
try
{
if (Sender == "") return;
if (Recipient == "") return;

System.Net.Mail.MailMessage Message = new
System.Net.Mail.MailMessage(Sender,Recipient,Subject,Body);
System.Net.Mail.SmtpClient MailClient = new System.Net.Mail.SmtpClient();
MailClient.Host = "LocalHost";
MailClient.Send(Message);
}
catch (Exception e)
{
LogException(fnName, e);
throw e;
}
}// function
 
S

sloan

Go here and download the source code.

http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry


Try to use other things like gmail or even your home isp.... as experiments.

But the source code will show you other options associated with the mail
object.
Both 1.1 and 2.0 samples are provided.

If you find a resolution, please post it.



if (Sender == "") return;
if (Recipient == "") return;

i'd throw an exception here, else you have no idea it didn't work.

if (string.IsNullOrEmpty ( Sender))
{
throw new ArgumentNullException ( "No Sender Supplied") ; //
}



OT
Here is a good link to exceptional handling:
http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx
 
A

Anthony Jones

Claire said:
I'm a noob at emailing from code and I need to add email capabilities to my
application.
The following code completes without exceptions but I'm not receiving any
test emails.
How do you debug this? Ive checked my bad mail folder, and other IIS similar
folders and they're empty.

What OS are you running? You have IIS with the SMTP server installed?
Did you look in the queue? Are you sending to a real address?
Can the mail classes be used without having a SMTP server running on
localhost?

Yes just set host to the FQDN of the smtp server.
Can you use any smtp server that's capable of being set up from a
PC, e.g. an ISP account?
Yes

If so, do you need to obtain the settings that you might find in an outlook
express email server tab?
Yes

Does the MailClient accept all the possible settings via properties?

Yes although you can't simply set username and password.

Typically you would place the host, port, username and password in the
application configuration file and simply use default constructor for
SmtpClient.
Are there any recommended freeware/opensource SMTP server .net controls out
there that I could plug into my application so I don't have to require the
user to do any configuration?

How is that possible? Unless you know what Server and credential
requirements are your going to need to acquire them somehow.
 

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