Solved

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

Posted on 2008-10-09
3
525 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 30

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

710 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