473,761 Members | 8,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to send email with vs2005?

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:t elcom'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.UseDefau ltCredentials = false;
client.Credenti als = new System.Net.Netw orkCredential(" uid", "pwd");
//I also try to use full email address to replace uid. It didn't work.
client.Delivery Method = SmtpDeliveryMet hod.Network;

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

"Body");
message.BodyEnc oding = System.Text.Enc oding.UTF8;
message.IsBodyH tml = true;

try
{
client.Send(mes sage);
Response.Write( "Email successfully sent.");
}
catch (Exception ex)
{
Response.Write( "Send Email Failed." + ex.ToString()); ;
}
===============
Mar 15 '07 #1
16 4755
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:t elcom'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.UseDefau ltCredentials = false;
client.Credenti als = new System.Net.Netw orkCredential(" uid", "pwd");
//I also try to use full email address to replace uid. It didn't work.
client.Delivery Method = SmtpDeliveryMet hod.Network;

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

"Body");
message.BodyEnc oding = System.Text.Enc oding.UTF8;
message.IsBodyH tml = true;

try
{
client.Send(mes sage);
Response.Write( "Email successfully sent.");
}
catch (Exception ex)
{
Response.Write( "Send Email Failed." + ex.ToString()); ;
}
===============
Mar 15 '07 #2
"Chef" <Ch**@discussio ns.microsoft.co mwrote in message
news:7A******** *************** ***********@mic rosoft.com...
but I cann't use this code below to send email.
What happens when you try...?
Mar 15 '07 #3
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:t elcom'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.UseDefau ltCredentials = false;
client.Credenti als = new System.Net.Netw orkCredential(" uid", "pwd");
//I also try to use full email address to replace uid. It didn't work.
client.Delivery Method = SmtpDeliveryMet hod.Network;

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

"Body");
message.BodyEnc oding = System.Text.Enc oding.UTF8;
message.IsBodyH tml = true;

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

"Send Email Failed.System.N et.Mail.SmtpExc eption: The operation has timed
out. at System.Net.Mail .SmtpClient.Sen d(MailMessage message) at
MainPage.Button 1_Click(Object sender, EventArgs e) in c:\Programming in
Class\ThreePage s\MainPage.aspx .cs:line 94 "

"Mark Rae" wrote:
"Chef" <Ch**@discussio ns.microsoft.co mwrote in message
news:7A******** *************** ***********@mic rosoft.com...
but I cann't use this code below to send email.

What happens when you try...?
Mar 15 '07 #5
"Chef" <Ch**@discussio ns.microsoft.co mwrote in message
news:FF******** *************** ***********@mic rosoft.com...
"Send Email Failed.System.N et.Mail.SmtpExc eption: The operation has timed
out. at System.Net.Mail .SmtpClient.Sen d(MailMessage message) at
MainPage.Button 1_Click(Object sender, EventArgs e) in c:\Programming in
Class\ThreePage s\MainPage.aspx .cs:line 94 "
Indulge me - what does line 94 contain...? I'm assuming it's:

client.Send(mes sage);
Mar 15 '07 #6
client.Send(mes sage); //line 94

"Mark Rae" wrote:
"Chef" <Ch**@discussio ns.microsoft.co mwrote in message
news:FF******** *************** ***********@mic rosoft.com...
"Send Email Failed.System.N et.Mail.SmtpExc eption: The operation has timed
out. at System.Net.Mail .SmtpClient.Sen d(MailMessage message) at
MainPage.Button 1_Click(Object sender, EventArgs e) in c:\Programming in
Class\ThreePage s\MainPage.aspx .cs:line 94 "

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

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

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**@discussio ns.microsoft.co mwrote in message
news:7A******** *************** ***********@mic rosoft.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:tel com'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.UseDefau ltCredentials = false;
client.Credenti als = new System.Net.Netw orkCredential(" uid",
"pwd");
//I also try to use full email address to replace uid. It didn't work.
client.Delivery Method = SmtpDeliveryMet hod.Network;

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

"Body");
message.BodyEnc oding = System.Text.Enc oding.UTF8;
message.IsBodyH tml = true;

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

Mar 15 '07 #8
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**@discussio ns.microsoft.co mwrote in message
news:7A******** *************** ***********@mic rosoft.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:tel com'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.UseDefau ltCredentials = false;
client.Credenti als = new System.Net.Netw orkCredential(" uid",
"pwd");
//I also try to use full email address to replace uid. It didn't work.
client.Delivery Method = SmtpDeliveryMet hod.Network;

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

"Body");
message.BodyEnc oding = System.Text.Enc oding.UTF8;
message.IsBodyH tml = true;

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


Mar 15 '07 #9
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**@discussio ns.microsoft.co mwrote in message
news:7A******** *************** ***********@mic rosoft.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:tel com'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.UseDefau ltCredentials = false;
client.Credenti als = new System.Net.Netw orkCredential(" uid",
"pwd");
//I also try to use full email address to replace uid. It didn't work.
client.Delivery Method = SmtpDeliveryMet hod.Network;

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

"Body");
message.BodyEnc oding = System.Text.Enc oding.UTF8;
message.IsBodyH tml = true;

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


Mar 15 '07 #10

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

Similar topics

11
12089
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to use PHP to get inside an OWA (Microsoft Outlook Web Access) website to send email that way? The reason I ask is because my corporate office is going to do away with our rogue SMTP server access and force everything through Exchange
0
3711
by: David Burson | last post by:
Hi, I have a VB.NET windows app that needs to automatically send a simple text email when my users run a new version of the app for the first time. I thought this would be simple, but after days of reading posts and testing, I see it is not - unless I'm missing something? I'm not an email guru. All of my users will be running at least Windows 2000, most on XP sp2. Some of my users will have Outlook, many will be using Outlook...
6
2980
by: ra294 | last post by:
I have an ASP.Net application that sends Emails on several pages. The problem is that when the mail server is down from some reason, the SmtpMail.Send hangs the application for one minute until I get an exception that the server is not reponsding. Is there a way to set a timeout for this operation (for example 5 seconds) ? Is there another solution for it (sending the mail in new thread ?) ? Thanks ra294@hotmail.com
14
9142
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my local default SMTP Server and my from address is a valid Yahoo/Hotmail address. I have configures the local SMTP Server to allow the IP Address 127.0.0.1.
11
7725
by: hazz | last post by:
smtpClient.Send(message) is causing me problems as per specifics in the trace below. Email is sent but not without this error typically upon sending the second email, but sometimes when running the app, even the first time. The application will be required to be sending out repeated emails, about one every second or two. Must this be done asynchronously? Thank you. -Greg I get the generic error messages;
15
8592
by: cj | last post by:
How can I get a button in VB to send the contents of a text box via email in a manner similar to the "Send To\Mail Recipient" functionality that you can select via right clicking a file in Windows Explorer? I want the user to click a button and it lunch the users default email client and put the contents of a multi line text box in the body of the message and the contents of another text box in the title box and be sitting there read for...
2
4371
by: Andrew Hunot | last post by:
I have VB code in VS2003 which creates a HttpWebRequest and performs a POST operation to a remote URL (an https site), which runs fine and receives a valid response. However exactly the same code in VS2005 (to the same site with the same data) causes an exception 'The underlying connection was closed: An unexpected error occurred on a send.' Any ideas as to why and what I can do to get around this?
2
4831
by: delusion7 | last post by:
This is what I need to do... - create an outlook message window (for example: have the outlook window pop-up) - attach my report1.rdlc to the message - the attachment(report1.rdlc) needs to be a .pdf format (using c# vs2005 pro team ed.)
9
77440
by: Mahernoz | last post by:
Can i send an email from JavaScript? Is it possible? If yes please the code to send email using javascript...
0
9376
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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
9988
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...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
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.

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.