Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Claire - 24 Oct 2007 16:04 GMT
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
sloan - 24 Oct 2007 16:27 GMT
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

> I'm a noob at emailing from code and I need to add email capabilities to
> my application.
[quoted text clipped - 36 lines]
> }
> }// function
Anthony Jones - 24 Oct 2007 17:01 GMT
> 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.

> thank you
> Claire
[quoted text clipped - 20 lines]
> }
> }// function

Signature

Anthony Jones - MVP ASP/ASP.NET


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.