Solved

How to send an email message from "LocalHost" using C# and Asp.Net

Posted on 2008-10-09
3
514 Views
Last Modified: 2010-05-18
I have written some C# code to send out an email message from a server. I can not get it to work off of my local machine. Attached is a code snippet. Does anyone have any ideas what the problem is?
// This is in the web.config ->	<add key="wireUp_SMTPServer" value="localhost"/>
protected string smtpServerStr = ConfigurationSettings.AppSettings["wireUp_SMTPServer"];
StringBuilder strMsg = new StringBuilder();
strMsg.Append("Hello this is a test");
 
MailMessage myEmailObject = new MailMessage();
myEmailObject.To = strToEmail;  // Email address not shown here
myEmailObject.From = areunMailStr;
myEmailObject.Subject = "Welcome to our site";
myEmailObject.Body = strMsg.ToString();
myEmailObject.BodyFormat = MailFormat.Html;
SmtpMail.SmtpServer = smtpServerStr;
	try
	{
	  SmtpMail.Send(myEmailObject);
	  return true;
	}
	catch
	{
	return false;
	}

Open in new window

0
Comment
Question by:brgdotnet
3 Comments
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 40 total points
ID: 22684245
Unless the localhost is a SMTP server it will not work. You need to supply the address of a valid SMTP server in place of localhost.
0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 85 total points
ID: 22684249
0
 
LVL 2

Author Closing Comment

by:brgdotnet
ID: 31504909
Thank you!
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question