Solved

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

Posted on 2008-10-09
3
512 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 62

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now