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

How do I send an email?

First, I'm extremely new to C# and the Microsoft Visual Studio IDE. I am in
the middle of writing a small web application that communicates to a
database server and sends out email confirmations. I've got the database
connection going okay, but I'm having problems trying to find a good way to
send an email. I have found a couple products online, but buying a tool is
not an option. So I need to figure out how to use what I have.

I'm looking for a small coded example. If anyone has one, that would be
great. If not, can someone point me into a good direction.

Thanks,

Randel Bjorkquist
Nov 17 '05 #1
7 3132
Hello Randel,

Here's a sample. You'll need to add a reference to "System.Web" first.
using System;
using System.Web;
public void Send()
{

SmtpMail.SmtpServer = "NameOfYourMailServer" //usually mail.xxxxxx.com

MailMessage msg = new MailMessage();
msg.From = "yo*@yourhost.com";
msg.To = "so*****@somehost.com";
msg.Body = "Test Message";
msg.Subject = "Test";
msg.BodyFormat = MailFormat.Text;

SmtpMail.Send(msg);

}

First, I'm extremely new to C# and the Microsoft Visual Studio IDE. I
am in the middle of writing a small web application that communicates
to a database server and sends out email confirmations. I've got the
database connection going okay, but I'm having problems trying to find
a good way to send an email. I have found a couple products online,
but buying a tool is not an option. So I need to figure out how to
use what I have.

I'm looking for a small coded example. If anyone has one, that would
be great. If not, can someone point me into a good direction.

Thanks,

Randel Bjorkquist


Nov 17 '05 #2
Hey Brian,

Thanks for the extremely quick reply. I've tried your code, but it wont
compile for me. Some of the errors I'm getting are: "The type or namespace
name 'SmtpMail' could not be found..." and "The type or namespace name
'MailMessage' could not be found...". I'm using VS .NET 2003 Professional.
Is that the problem? Are these only availible in the Enterprise version?

I'll keep looking. But again, thanks for the help,

Randel

"Brian" <fa**@email.com> wrote in message
news:35********************@news.microsoft.com...
Hello Randel,

Here's a sample. You'll need to add a reference to "System.Web" first.
using System;
using System.Web;
public void Send()
{

SmtpMail.SmtpServer = "NameOfYourMailServer" //usually mail.xxxxxx.com

MailMessage msg = new MailMessage();
msg.From = "yo*@yourhost.com";
msg.To = "so*****@somehost.com";
msg.Body = "Test Message";
msg.Subject = "Test";
msg.BodyFormat = MailFormat.Text;

SmtpMail.Send(msg);

}

First, I'm extremely new to C# and the Microsoft Visual Studio IDE. I
am in the middle of writing a small web application that communicates
to a database server and sends out email confirmations. I've got the
database connection going okay, but I'm having problems trying to find
a good way to send an email. I have found a couple products online,
but buying a tool is not an option. So I need to figure out how to
use what I have.

I'm looking for a small coded example. If anyone has one, that would
be great. If not, can someone point me into a good direction.

Thanks,

Randel Bjorkquist


Nov 17 '05 #3
Hello Randel,

You need to make sure you add a reference to "System.Web".

In the "Solution Explorer" window, right-click on the "References" folder
under your project. Choose "Add Reference"
In the window that shows up, scroll down until you see "System.Web". Click
on it and choose "Select". Then click "Okay" at the bottom.

I left out the class struction from the example, here is a full example:

using System;
using System.Web;

namespace sandbox.SendEmailExample
{

class program
{

[STAThred]
static void Main(string[] args)
{

SmtpMail.SmtpServer = "NameOfYourMailServer" //usually
mail.xxxxxx.com

MailMessage msg = new MailMessage();
msg.From = "yo*@yourhost.com";
msg.To = "so*****@somehost.com";
msg.Body = "Test Message";
msg.Subject = "Test";
msg.BodyFormat = MailFormat.Text;
SmtpMail.Send(msg);
}

}

}

Hey Brian,

Thanks for the extremely quick reply. I've tried your code, but it
wont compile for me. Some of the errors I'm getting are: "The type or
namespace name 'SmtpMail' could not be found..." and "The type or
namespace name 'MailMessage' could not be found...". I'm using VS
.NET 2003 Professional. Is that the problem? Are these only availible
in the Enterprise version?

I'll keep looking. But again, thanks for the help,

Randel

"Brian" <fa**@email.com> wrote in message
news:35********************@news.microsoft.com...
Hello Randel,

Here's a sample. You'll need to add a reference to "System.Web"
first.

using System;
using System.Web;
public void Send()
{
SmtpMail.SmtpServer = "NameOfYourMailServer" //usually
mail.xxxxxx.com

MailMessage msg = new MailMessage();
msg.From = "yo*@yourhost.com";
msg.To = "so*****@somehost.com";
msg.Body = "Test Message";
msg.Subject = "Test";
msg.BodyFormat = MailFormat.Text;
SmtpMail.Send(msg);

}
First, I'm extremely new to C# and the Microsoft Visual Studio IDE.
I am in the middle of writing a small web application that
communicates to a database server and sends out email confirmations.
I've got the database connection going okay, but I'm having problems
trying to find a good way to send an email. I have found a couple
products online, but buying a tool is not an option. So I need to
figure out how to use what I have.

I'm looking for a small coded example. If anyone has one, that
would be great. If not, can someone point me into a good direction.

Thanks,

Randel Bjorkquist


Nov 17 '05 #4
Randel Bjorkquist wrote:
wont compile for me. Some of the errors I'm getting are: "The type
or namespace name 'SmtpMail' could not be found..."


It's a good example, but the poster left off the essential namespace. Add
"using System.Web.Mail" to your code.

By the way, you can find the docs for it here:

http://msdn.microsoft.com/library/en...temwebmail.asp
--
Chris Priede (pr****@panix.com)
Nov 17 '05 #5
Hey Brian,

I have the "System.Web" in my "Solution Explorer". When I created my
project, I created a new "ASP.NET Web Application" project and it looks to
me as if it added it.

The top of my *.aspx.cs file looks like this:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

I am correct in my thinking that I should be good to go? Or am I still
missing something?

Randel
"Brian" <fa**@email.com> wrote in message
news:35********************@news.microsoft.com...
Hello Randel,

You need to make sure you add a reference to "System.Web".

In the "Solution Explorer" window, right-click on the "References" folder
under your project. Choose "Add Reference"
In the window that shows up, scroll down until you see "System.Web".
Click on it and choose "Select". Then click "Okay" at the bottom.

I left out the class struction from the example, here is a full example:

using System;
using System.Web;

namespace sandbox.SendEmailExample
{

class program
{

[STAThred]
static void Main(string[] args)
{

SmtpMail.SmtpServer = "NameOfYourMailServer" //usually
mail.xxxxxx.com

MailMessage msg = new MailMessage();
msg.From = "yo*@yourhost.com";
msg.To = "so*****@somehost.com";
msg.Body = "Test Message";
msg.Subject = "Test";
msg.BodyFormat = MailFormat.Text;
SmtpMail.Send(msg);
}

}

}

Hey Brian,

Thanks for the extremely quick reply. I've tried your code, but it
wont compile for me. Some of the errors I'm getting are: "The type or
namespace name 'SmtpMail' could not be found..." and "The type or
namespace name 'MailMessage' could not be found...". I'm using VS
.NET 2003 Professional. Is that the problem? Are these only availible
in the Enterprise version?

I'll keep looking. But again, thanks for the help,

Randel

"Brian" <fa**@email.com> wrote in message
news:35********************@news.microsoft.com...
Hello Randel,

Here's a sample. You'll need to add a reference to "System.Web"
first.

using System;
using System.Web;
public void Send()
{
SmtpMail.SmtpServer = "NameOfYourMailServer" //usually
mail.xxxxxx.com

MailMessage msg = new MailMessage();
msg.From = "yo*@yourhost.com";
msg.To = "so*****@somehost.com";
msg.Body = "Test Message";
msg.Subject = "Test";
msg.BodyFormat = MailFormat.Text;
SmtpMail.Send(msg);

}

First, I'm extremely new to C# and the Microsoft Visual Studio IDE.
I am in the middle of writing a small web application that
communicates to a database server and sends out email confirmations.
I've got the database connection going okay, but I'm having problems
trying to find a good way to send an email. I have found a couple
products online, but buying a tool is not an option. So I need to
figure out how to use what I have.

I'm looking for a small coded example. If anyone has one, that
would be great. If not, can someone point me into a good direction.

Thanks,

Randel Bjorkquist


Nov 17 '05 #6
Thanks Chris,

That fixed my problem. The code example that Brain posted compiled just
peachy.

Thanks again to both of you, I really appreciated it.

Randel Bjorkquist

"Chris Priede" <pr****@panix.com> wrote in message
news:eZ**************@TK2MSFTNGP10.phx.gbl...
Randel Bjorkquist wrote:
wont compile for me. Some of the errors I'm getting are: "The type
or namespace name 'SmtpMail' could not be found..."


It's a good example, but the poster left off the essential namespace. Add
"using System.Web.Mail" to your code.

By the way, you can find the docs for it here:

http://msdn.microsoft.com/library/en...temwebmail.asp
--
Chris Priede (pr****@panix.com)

Nov 17 '05 #7
Randel Bjorkquist wrote:
First, I'm extremely new to C# and the Microsoft Visual Studio IDE. I am in
the middle of writing a small web application that communicates to a
database server and sends out email confirmations. I've got the database
connection going okay, but I'm having problems trying to find a good way to
send an email. I have found a couple products online, but buying a tool is
not an option. So I need to figure out how to use what I have.

I'm looking for a small coded example. If anyone has one, that would be
great. If not, can someone point me into a good direction.

Thanks,

Randel Bjorkquist

Have a look into SmtpMail in System.Web.Mail in the help files. This is
what I use to send out mail:
SmtpMail.SmtpServer = "smtp.yourISP.com";
SmtpMail.Send(emailmsg);

There is rather more to it than that but.....

If you have access to Outlook, you can also access that through interop
and use that to send mail. See
http://www.microeye.com/resources/res_tech_vsnet.htm
Nov 17 '05 #8

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

Similar topics

11
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...
40
by: ian | last post by:
Hi, I'm a newbie (oh no I can here you say.... another one...) How can I get Python to send emails using the default windows email client (eg outlook express)? I thought I could just do the...
0
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...
9
by: Bob Jones | last post by:
We have developed a commercial ASP.net application (personal nutrition management and tracking); we want to send smtp email from within it. For our development box, we use WinXP Pro, IIS 5.5,...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
14
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...
8
by: shapper | last post by:
Hello, I am trying to send an email using Asp.Net 2.0. I am getting the following error: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: No such...
9
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...
2
by: Malli mindwave | last post by:
Hi, We are using the yahoowebHostiing service for my company website, In that one screen of the SendComments/FeedBack section is there, I'm basically dot.net develeoper ,but yahoowebhosting not...
5
by: Mike | last post by:
I have a page with a textbox that a user can enter in mutliple email addresses such as: user1@yahoo.com;user2@yahoo.com;user3@gmail.com; and so on, I then have a foreach loop to get all of the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
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...

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.