Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

18 Experts available now in Live!

Get 1:1 Help Now