473,385 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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,Subje ct,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
Oct 24 '07 #1
2 3194
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/archi...16/396787.aspx
"Claire" <cc@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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,Subje ct,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

Oct 24 '07 #2
"Claire" <cc@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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

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,Subje ct,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
--
Anthony Jones - MVP ASP/ASP.NET
Oct 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: HoustonComputerGuy | last post by:
I am working on getting my web applications moved to .Net 2.0 and am having some problems with System.Net.Mail. I get the following error when sending the mail: System.Net.Mail.SmtpException was...
2
by: Alejandro Kwiatkowski | last post by:
MailMessage message = new MailMessage(); message.From = new MailAddress("ak@eka.com.ar","Alejandro"); message.To.Add("ak@eka.com.ar"); message.Subject = "Something"; message.Body =...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
2
by: Tim Cowan | last post by:
Hi, I am using .NET 2.0 and I want to send mail that uses SMTP authorization. I have found this in the help: client.Credentials = System.Net.CredentialCache.DefaultCredentials; My question...
0
by: howardr101 | last post by:
Hi, Have hunted around on the groups and can't find anything, hence. I've tried this against 2 mail servers (mailtraq and hmailserver) and it occus with both. The problems seems to be that...
1
by: Sachin1234 | last post by:
Hi , I am getting the error in system log that " The remote server did not respond to a connection attempt." i am using following code for sending mail /**************** Work for...
1
by: WIzmanG | last post by:
Hi all I am having trouble with sending email via a C#2.0 application, I use the same settings as I use in Outlook but I cannot get email to send. I am trying to use SSL on port 465 and get the...
11
by: Ed Bitzer | last post by:
I have been able using the namespace System.Web.Mail and its method Smtp.mail.send to mail simple text messages to a small group within our 55 and older community. I need help expanding the...
5
by: Henry Stock | last post by:
I am trying to understand the following error: Any thing you can tell me about this is appreciated. Security Exception Description: The application attempted to perform an operation not allowed...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.