Link to home
Start Free TrialLog in
Avatar of brgdotnet
brgdotnetFlag for United States of America

asked on

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

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

SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of brgdotnet

ASKER

Thank you!