473,761 Members | 2,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(strin g 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(Se nder,Recipient, Subject,Body);
System.Net.Mail .SmtpClient MailClient = new System.Net.Mail .SmtpClient();
MailClient.Host = "LocalHost" ;
MailClient.Send (Message);
}
catch (Exception e)
{
LogException(fn Name, e);
throw e;
}
}// function
Oct 24 '07 #1
2 3216
Go here and download the source code.

http://sholliday.space s.live.com/Blog/cns!A68482B9628 A842A!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.IsNullO rEmpty ( Sender))
{
throw new ArgumentNullExc eption ( "No Sender Supplied") ; //
}

OT
Here is a good link to exceptional handling:
http://blogs.msdn.com/kcwalina/archi...16/396787.aspx
"Claire" <cc@nospam.comw rote in message
news:%2******** ********@TK2MSF TNGP02.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(strin g 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(Se nder,Recipient, Subject,Body);
System.Net.Mail .SmtpClient MailClient = new System.Net.Mail .SmtpClient();
MailClient.Host = "LocalHost" ;
MailClient.Send (Message);
}
catch (Exception e)
{
LogException(fn Name, e);
throw e;
}
}// function

Oct 24 '07 #2
"Claire" <cc@nospam.comw rote in message
news:%2******** ********@TK2MSF TNGP02.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(strin g 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(Se nder,Recipient, Subject,Body);
System.Net.Mail .SmtpClient MailClient = new System.Net.Mail .SmtpClient();
MailClient.Host = "LocalHost" ;
MailClient.Send (Message);
}
catch (Exception e)
{
LogException(fn Name, 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
57669
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 unhandled by user code Message="Failure sending mail." Source="System" StackTrace: at System.Net.Mail.SmtpClient.Send(MailMessage message) at System.Net.Mail.SmtpClient.Send(String from, String
2
1940
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 = "Something else";
1
8182
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 the members of my organization. I think my problem is incorrectly setting the settings on my server or an authentication problem. Here is the code I have written to send a test message: -----Code Begins: Sensitive Information Replaced by -----...
2
2652
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 is how do I set the username and password? Say the username is bob@home.com and the password is onions, how do I set this? The values could be different on a user by user basis, so I need to apply the settings from
0
2408
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 when the SMTPClient attaches to the server and the server sends it greeting message, if anything other than +OK is received by the client it throws an exception and falls over.
1
1397
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 sending mail ****************/ // All the mail settings are extracted from the web.config file. string from = ConfigurationManager.AppSettings.ToString(); string SMTPServer =...
1
3279
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 error below, If I disable SSL and use port 587 all goes well. I have been Googling for 2 days without success and this seems to be a common problem.
11
3511
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 programs capabilities. Searching this forum I did not find any related information so if I have chosen poorly, I would appreciate a suggestion of a more appropriate dotnet forum. Now what I wish is the ability to send bcc's rather than to: (would be...
5
8331
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 by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: for the permission of type
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.