473,386 Members | 1,706 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,386 software developers and data experts.

System.Net.Mail.SmtpException how do I send mail in .Net 2.0

Hi all,

I'm trying to use .Net.Mail to send email in my program but somehow it
always throws me error. I have checked everything in the configuration:
username, password, smtpserver, smtp port... are properly input. Could
someone please kindly point me the way out. Thanks in advance.

Below is my EmailSender class:
/***************************************/

using System;
using System.Text;
using System.Net;
using System.Net.Mail;

class EmailSender
{
string toEmail, toName, fromEmail, fromName, emailSubject,
emailBody, smtpServer, username, password;
int smtpPort;

public EmailSender()
{
toEmail = "so******@mydomain.com";
toName = "somebody";
fromEmail = "te*********@mydomain.com";
fromName = "Test account";
emailSubject = "Email function testing";
emailBody = "Testing...";
smtpServer = "mail.mydomain.com";
username = "te*********@mydomain.com";
password = "testaccountPW";
smtpPort = 25;
}

public EmailSender(string toEmail, string toName, string
fromEmail, string fromName, string emailSubject, string emailBody,
string smtpServer, string username, string password, int smtpPort)
{
this.toEmail = toEmail;
this.toName = toName;
this.fromEmail = fromEmail;
this.fromName = fromName;
this.emailSubject = emailSubject;
this.emailBody = emailBody;
this.smtpServer = smtpServer;
this.username = username;
this.password = password;
this.smtpPort = smtpPort;
}

public void sendMail(){
try
{
MailMessage mail = new MailMessage(fromEmail, toEmail,
emailSubject, emailBody);
mail.IsBodyHtml = false;
SmtpClient client = new SmtpClient(smtpServer,
smtpPort);
//client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(username,
password);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
//client.EnableSsl = true;
client.Timeout = 100000;
client.Send(mail);

Console.WriteLine("Mail Sent");
mail.Dispose();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
} //end SendMail()

} //end Class

/************************************************** *****/
Then I call the class:

/*************************************************/
EmailSender testmail = new EmailSender();
testmail.sendMail();
/*********************************************/

After 1 or 2 minutes, I receive the following error message:

/*************
Failure sending mail.
A first chance exception of type 'System.Net.Mail.SmtpException'
occurred in System.dll
*************/

May 17 '06 #1
0 6361

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

Similar topics

2
by: Mark Carter | last post by:
I'm trying to create a mail server in Twisted. I either get SMTPSenderRefused or SMTPException: SMTP AUTH extension not supported by server. What do I need to do to get it to work?
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...
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...
4
by: Bob | last post by:
This code snippet works fine (vs 2005) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim message As New MailMessage() Try...
1
by: Bob | last post by:
Vs2005 - Framework2. Just to let all of you know. I have found that I can not use an application to send e-mails using the system,net.mail namespace while Outlook express is opened on the same...
2
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to...
11
by: justsome_newbie | last post by:
Hello experts! I'm trying to send mail from my C# Asp.Net webpage. I used the code samples at www.systemnetmail.com but it still won't send. I think the problem is on the iis or exchange server...
0
by: Neo Geshel | last post by:
I am experiencing an inconsistency with System.Net.Mail. I have a web form on a site. The form gets filled, and one copy gets sent to the recipient (info@domain.com). This works just fine. ...
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...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.