Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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