By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

How to send email with vs2005?

P: n/a
I can use outlook2003 to send email,but I cann't use this code below to send
email.
Please help me to test this code and instruct me how to solve this problem
in detail.

software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.。-- I also tried to connect computer to modem directly,but I can
surf internet, not send email with code.

=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid", "pwd");
//I also try to use full email address to replace uid. It didn't work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",

"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;

try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============
Mar 15 '07 #1
Share this Question
Share on Google+
16 Replies


P: n/a
Is your logon name "uid" and your password "pwd"? If not, change these values
to your logon id and password. That should get things running.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Chef" wrote:
I can use outlook2003 to send email,but I cann't use this code below to send
email.
Please help me to test this code and instruct me how to solve this problem
in detail.

software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.。-- I also tried to connect computer to modem directly,but I can
surf internet, not send email with code.

=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid", "pwd");
//I also try to use full email address to replace uid. It didn't work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",

"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;

try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============
Mar 15 '07 #2

P: n/a
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
but I cann't use this code below to send email.
What happens when you try...?
Mar 15 '07 #3

P: n/a
I used my real user name and password to replace "uid" and "pwd" in the code.

"Cowboy (Gregory A. Beamer) - MVP" wrote:
Is your logon name "uid" and your password "pwd"? If not, change these values
to your logon id and password. That should get things running.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Chef" wrote:
I can use outlook2003 to send email,but I cann't use this code below to send
email.
Please help me to test this code and instruct me how to solve this problem
in detail.

software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.。-- I also tried to connect computer to modem directly,but I can
surf internet, not send email with code.

=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid", "pwd");
//I also try to use full email address to replace uid. It didn't work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",

"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;

try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============
Mar 15 '07 #4

P: n/a
It happend below!

"Send Email Failed.System.Net.Mail.SmtpException: The operation has timed
out. at System.Net.Mail.SmtpClient.Send(MailMessage message) at
MainPage.Button1_Click(Object sender, EventArgs e) in c:\Programming in
Class\ThreePages\MainPage.aspx.cs:line 94 "

"Mark Rae" wrote:
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
but I cann't use this code below to send email.

What happens when you try...?
Mar 15 '07 #5

P: n/a
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:FF**********************************@microsof t.com...
"Send Email Failed.System.Net.Mail.SmtpException: The operation has timed
out. at System.Net.Mail.SmtpClient.Send(MailMessage message) at
MainPage.Button1_Click(Object sender, EventArgs e) in c:\Programming in
Class\ThreePages\MainPage.aspx.cs:line 94 "
Indulge me - what does line 94 contain...? I'm assuming it's:

client.Send(message);
Mar 15 '07 #6

P: n/a
client.Send(message); //line 94

"Mark Rae" wrote:
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:FF**********************************@microsof t.com...
"Send Email Failed.System.Net.Mail.SmtpException: The operation has timed
out. at System.Net.Mail.SmtpClient.Send(MailMessage message) at
MainPage.Button1_Click(Object sender, EventArgs e) in c:\Programming in
Class\ThreePages\MainPage.aspx.cs:line 94 "

Indulge me - what does line 94 contain...? I'm assuming it's:

client.Send(message);
Mar 15 '07 #7

P: n/a

I have downloadable examples here:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)
http://sholliday.spaces.live.com/blog/
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I can use outlook2003 to send email,but I cann't use this code below to
send
email.
Please help me to test this code and instruct me how to solve this problem
in detail.

software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.?-- I also tried to connect computer to modem directly,but I can
surf internet, not send email with code.

=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid",
"pwd");
//I also try to use full email address to replace uid. It didn't work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",

"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;

try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============

Mar 15 '07 #8

P: n/a
Thank you very much.

Your code is really helpfull. It worked with port 587, not 465 on my pc. One
more thing, could you tell me what the problem is with my code?
"sloan" wrote:
>
I have downloadable examples here:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)
http://sholliday.spaces.live.com/blog/
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I can use outlook2003 to send email,but I cann't use this code below to
send
email.
Please help me to test this code and instruct me how to solve this problem
in detail.

software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.?-- I also tried to connect computer to modem directly,but I can
surf internet, not send email with code.

=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid",
"pwd");
//I also try to use full email address to replace uid. It didn't work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",

"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;

try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============


Mar 15 '07 #9

P: n/a
If I use gmail as smtp server, what the different between port 587 and port
465 is?

I just check gmail online help, it recommend that we use port 465. Why? Waht
is the reason you used port 587?

Thanks in advance!

"sloan" wrote:
>
I have downloadable examples here:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and 2.0)
http://sholliday.spaces.live.com/blog/
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I can use outlook2003 to send email,but I cann't use this code below to
send
email.
Please help me to test this code and instruct me how to solve this problem
in detail.

software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.?-- I also tried to connect computer to modem directly,but I can
surf internet, not send email with code.

=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid",
"pwd");
//I also try to use full email address to replace uid. It didn't work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",

"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;

try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============


Mar 15 '07 #10

P: n/a

I have no idea.

Experimentation showed that for 1.1 .. one of those ports worked.
and for 2.0, only the other one worked.
????

Huh? I'm with you, but I have no idea.


"Chef" <Ch**@discussions.microsoft.comwrote in message
news:21**********************************@microsof t.com...
If I use gmail as smtp server, what the different between port 587 and
port
465 is?

I just check gmail online help, it recommend that we use port 465. Why?
Waht
is the reason you used port 587?

Thanks in advance!

"sloan" wrote:

I have downloadable examples here:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and
2.0)
http://sholliday.spaces.live.com/blog/
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I can use outlook2003 to send email,but I cann't use this code below
to
send
email.
Please help me to test this code and instruct me how to solve this
problem
in detail.
>
>
>
software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.?-- I also tried to connect computer to modem directly,but I
can
surf internet, not send email with code.
>
=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid",
"pwd");
//I also try to use full email address to replace uid. It didn't work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;
>
System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",
>
"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
>
try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============

Mar 15 '07 #11

P: n/a

Not really, unless I was sitting next to you (or at least on your network).

I've found smtp email sending is experimentation sometimes.

Thus why I built the "smarter email configuration" model.

Because I'd get different behavior

at work
at home
using dialup somewhere.

Sometimes its an art, not a science.


"Chef" <Ch**@discussions.microsoft.comwrote in message
news:31**********************************@microsof t.com...
Thank you very much.

Your code is really helpfull. It worked with port 587, not 465 on my pc.
One
more thing, could you tell me what the problem is with my code?
"sloan" wrote:

I have downloadable examples here:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and
2.0)
http://sholliday.spaces.live.com/blog/
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I can use outlook2003 to send email,but I cann't use this code below
to
send
email.
Please help me to test this code and instruct me how to solve this
problem
in detail.
>
>
>
software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.?-- I also tried to connect computer to modem directly,but I
can
surf internet, not send email with code.
>
=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid",
"pwd");
//I also try to use full email address to replace uid. It didn't work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;
>
System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",
>
"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
>
try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============

Mar 15 '07 #12

P: n/a
Thank you very much and have a nice day!

"sloan" wrote:
>
I have no idea.

Experimentation showed that for 1.1 .. one of those ports worked.
and for 2.0, only the other one worked.
????

Huh? I'm with you, but I have no idea.


"Chef" <Ch**@discussions.microsoft.comwrote in message
news:21**********************************@microsof t.com...
If I use gmail as smtp server, what the different between port 587 and
port
465 is?

I just check gmail online help, it recommend that we use port 465. Why?
Waht
is the reason you used port 587?

Thanks in advance!

"sloan" wrote:
>
I have downloadable examples here:
>
2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and
2.0)
http://sholliday.spaces.live.com/blog/
>
>
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I can use outlook2003 to send email,but I cann't use this code below
to
send
email.
Please help me to test this code and instruct me how to solve this
problem
in detail.



software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.?-- I also tried to connect computer to modem directly,but I
can
surf internet, not send email with code.

=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid",
"pwd");
//I also try to use full email address to replace uid. It didn't work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",

"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;

try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============
>
>
>


Mar 15 '07 #13

P: n/a
re:
!Experimentation showed that for 1.1 .. one of those ports worked.
!and for 2.0, only the other one worked.

Check for code differences.

The port used depends on your ISP's ( Gmail, in this case ) server's settings,
and not on any code you write. The port is determined by your ISP, not by your code.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"sloan" <sl***@ipass.netwrote in message news:uT**************@TK2MSFTNGP03.phx.gbl...
>
I have no idea.

Experimentation showed that for 1.1 .. one of those ports worked.
and for 2.0, only the other one worked.
????

Huh? I'm with you, but I have no idea.


"Chef" <Ch**@discussions.microsoft.comwrote in message
news:21**********************************@microsof t.com...
>If I use gmail as smtp server, what the different between port 587 and
port
>465 is?

I just check gmail online help, it recommend that we use port 465. Why?
Waht
>is the reason you used port 587?

Thanks in advance!

"sloan" wrote:
>
I have downloadable examples here:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and
2.0)
http://sholliday.spaces.live.com/blog/
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I can use outlook2003 to send email,but I cann't use this code below
to
send
email.
Please help me to test this code and instruct me how to solve this
problem
in detail.

software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.?-- I also tried to connect computer to modem directly,but I
can
surf internet, not send email with code.

=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("uid",
"pwd");
//I also try to use full email address to replace uid. It didn't work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",

"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;

try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============


Mar 15 '07 #14

P: n/a
Juan
I agree with you.. except for the gmail smtp server.

1.1 framework likes port 465
2.0 Framework, my tests show that gmail likes port 587

I can't explain only, I can only say that was how it played out.

"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
re:
!Experimentation showed that for 1.1 .. one of those ports worked.
!and for 2.0, only the other one worked.

Check for code differences.

The port used depends on your ISP's ( Gmail, in this case ) server's
settings,
and not on any code you write. The port is determined by your ISP, not by
your code.
>
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"sloan" <sl***@ipass.netwrote in message
news:uT**************@TK2MSFTNGP03.phx.gbl...

I have no idea.

Experimentation showed that for 1.1 .. one of those ports worked.
and for 2.0, only the other one worked.
????

Huh? I'm with you, but I have no idea.


"Chef" <Ch**@discussions.microsoft.comwrote in message
news:21**********************************@microsof t.com...
If I use gmail as smtp server, what the different between port 587 and
port
465 is?

I just check gmail online help, it recommend that we use port 465. Why?
Waht
is the reason you used port 587?

Thanks in advance!

"sloan" wrote:


I have downloadable examples here:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and
2.0)
http://sholliday.spaces.live.com/blog/
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I can use outlook2003 to send email,but I cann't use this code
below
to
send
email.
Please help me to test this code and instruct me how to solve this
problem
in detail.
>
>
>
software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.?-- I also tried to connect computer to modem
directly,but I
can
surf internet, not send email with code.
>
=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new
System.Net.NetworkCredential("uid",
"pwd");
//I also try to use full email address to replace uid. It didn't
work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;
>
System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",
>
"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
>
try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============



Mar 15 '07 #15

P: n/a
587 is the assigned SMTP port for applications which support TLS.
465 is the assigned SMTP port for applications which support SSL.

The Transport Layer Security (TLS) 1.0 protocol is disabled in the .NET Framework 1.1.
By default, only the Secure Sockets Layer (SSL) 3.0 protocol is enabled in .Net 1.1.

That means that, if you use the .Net Framework 1.1 to send mail, you *must* use port 465.

By default, TLS 1.0 and SSL 3.0 are *both* enabled in the Microsoft .NET Framework 2.0.

That means that, if you use the .Net Framework 2.0 to send mail,
you can use port 465 *or* you can use port 587, depending on the security protocol you enable.

The port you need to use *really* depends on which security layer your application uses.

re:
I can't explain only, I can only say that was how it played out.
The above is the technical explanation. :-)

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"sloan" <sl***@ipass.netwrote in message news:%2****************@TK2MSFTNGP03.phx.gbl...
Juan
I agree with you.. except for the gmail smtp server.

1.1 framework likes port 465
2.0 Framework, my tests show that gmail likes port 587
I can't explain only, I can only say that was how it played out.

"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>re:
!Experimentation showed that for 1.1 .. one of those ports worked.
!and for 2.0, only the other one worked.

Check for code differences.

The port used depends on your ISP's ( Gmail, in this case ) server's
settings,
>and not on any code you write. The port is determined by your ISP, not by
your code.
>>
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"sloan" <sl***@ipass.netwrote in message
news:uT**************@TK2MSFTNGP03.phx.gbl...
>
I have no idea.

Experimentation showed that for 1.1 .. one of those ports worked.
and for 2.0, only the other one worked.
????

Huh? I'm with you, but I have no idea.


"Chef" <Ch**@discussions.microsoft.comwrote in message
news:21**********************************@microsof t.com...
If I use gmail as smtp server, what the different between port 587 and
port
465 is?

I just check gmail online help, it recommend that we use port 465. Why?
Waht
is the reason you used port 587?

Thanks in advance!

"sloan" wrote:
I have downloadable examples here:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1 and
2.0)
http://sholliday.spaces.live.com/blog/
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I can use outlook2003 to send email,but I cann't use this code
below
to
send
email.
Please help me to test this code and instruct me how to solve this
problem
in detail.

software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects two
computers.?-- I also tried to connect computer to modem
directly,but I
can
surf internet, not send email with code.

=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new
System.Net.NetworkCredential("uid",
"pwd");
//I also try to use full email address to replace uid. It didn't
work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",

"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;

try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString()); ;
}
===============





Mar 15 '07 #16

P: n/a
Aha,

Thanks for the explanation.


"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2***************@TK2MSFTNGP04.phx.gbl...
587 is the assigned SMTP port for applications which support TLS.
465 is the assigned SMTP port for applications which support SSL.

The Transport Layer Security (TLS) 1.0 protocol is disabled in the .NET
Framework 1.1.
By default, only the Secure Sockets Layer (SSL) 3.0 protocol is enabled in
..Net 1.1.
>
That means that, if you use the .Net Framework 1.1 to send mail, you
*must* use port 465.
>
By default, TLS 1.0 and SSL 3.0 are *both* enabled in the Microsoft .NET
Framework 2.0.
>
That means that, if you use the .Net Framework 2.0 to send mail,
you can use port 465 *or* you can use port 587, depending on the security
protocol you enable.
>
The port you need to use *really* depends on which security layer your
application uses.
>
re:
I can't explain only, I can only say that was how it played out.

The above is the technical explanation. :-)

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"sloan" <sl***@ipass.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Juan

I agree with you.. except for the gmail smtp server.

1.1 framework likes port 465
2.0 Framework, my tests show that gmail likes port 587
I can't explain only, I can only say that was how it played out.


"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
re:
!Experimentation showed that for 1.1 .. one of those ports worked.
!and for 2.0, only the other one worked.

Check for code differences.

The port used depends on your ISP's ( Gmail, in this case ) server's
settings,
and not on any code you write. The port is determined by your ISP, not
by
your code.
>
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"sloan" <sl***@ipass.netwrote in message
news:uT**************@TK2MSFTNGP03.phx.gbl...

I have no idea.

Experimentation showed that for 1.1 .. one of those ports worked.
and for 2.0, only the other one worked.
????

Huh? I'm with you, but I have no idea.


"Chef" <Ch**@discussions.microsoft.comwrote in message
news:21**********************************@microsof t.com...
If I use gmail as smtp server, what the different between port 587
and
port
465 is?

I just check gmail online help, it recommend that we use port 465.
Why?
Waht
is the reason you used port 587?

Thanks in advance!

"sloan" wrote:


I have downloadable examples here:

2/8/2006
Smarter Email/Smtp setup with DotNet Configuration Sections (1.1
and
2.0)
http://sholliday.spaces.live.com/blog/
"Chef" <Ch**@discussions.microsoft.comwrote in message
news:7A**********************************@microsof t.com...
I can use outlook2003 to send email,but I cann't use this code
below
to
send
email.
Please help me to test this code and instruct me how to solve
this
problem
in detail.
>
>
>
software environment: VS2005 + XP.-- I have disabled firewall
hardware enviornmnet:telcom's modem connects hub,hub connects
two
computers.?-- I also tried to connect computer to modem
directly,but I
can
surf internet, not send email with code.
>
=============================
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 465;
client.UseDefaultCredentials = false;
client.Credentials = new
System.Net.NetworkCredential("uid",
"pwd");
//I also try to use full email address to replace uid. It didn't
work.
client.DeliveryMethod = SmtpDeliveryMethod.Network;
>
System.Net.Mail.MailMessage message = new
MailMessage("ui*@hotmail.com", "ui*@hotmail.com", "Subject",
>
"Body");
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
>
try
{
client.Send(message);
Response.Write("Email successfully sent.");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." +
ex.ToString()); ;
}
===============






Mar 15 '07 #17

This discussion thread is closed

Replies have been disabled for this discussion.