[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

Email using ASP.NET C#

I am writing an app to send email using asp.net. When i run it it give me this error
"Could not access 'CDO.Message' object."
Is there any way around this. This is my code

try
{
 MailMessage Mailer = new MailMessage();
Mailer.From = txtFrom.Text;
Mailer.To = txtTo.Text;
 Mailer.Subject = txtSubject.Text;
 Mailer.Body = txtBody.Text;
 Mailer.BodyFormat = System.Web.Mail.MailFormat.Html;
 SmtpMail.Send(Mailer);
lblResult.Text = "Page successfully sent!";
 }
catch(Exception ex)
{
 lblResult.Text = "An error occurred: " + ex.ToString();
 }


Also is there any other way to send email, apart from SMTP.

Thanks
0
CDFA_Inc
Asked:
CDFA_Inc
  • 4
1 Solution
 
CDFA_IncAuthor Commented:
urgent
0
 
zahabyCommented:
Specify a valid mail server for the SmtpMail.SmtpServer property. If that property is not set, at least set it to 127.0.0.1. For example:
SmtpMail.SmtpServer = "127.0.0.1"
0
 
zahabyCommented:
If you are using "localhost" or "127.0.0.1" as the SmtpMail.SmtpServer, you may not have permissions to relay through the IIS SMTP Service. To allow access, open up the IIS Admin MMC. Locate the SMTP Virtual Server, and right-click, then select Properties. On the Access tab, click the Relay button. In the Relay Restrictions dialog, grant your IP address (127.0.0.1) to the Computers listbox. Close down all dialogs, and restart the SMTP Service.
========================
If you are using "localhost" or "127.0.0.1" as the SmtpMail.SmtpServer, make sure Anonymous access is allowd. To allow access, open up the IIS Admin MMC. Locate the SMTP Virtual Server, and right-click, then select Properties. On the Access tab, click the Authentication button. Be sure "Anonymous Access" is the only checkbox checked. Close down all dialogs, and restart the SMTP Service.

========================
The email address does not have a valid TO address. After iterating through the InnerExceptions, you may find this error message actually has to do with relaying. Try sending a test email to an email address that exists on the server specified by SmtpMail.SmtpServer. If you can send an email to that server, then it is a relay issue. Talk to your mail server administrator about letting your code relay through the mail server.

========================
Use a real FROM address that exists on the SmtpMail.SmtpServer. Do not use something like "asdf@asdf.com", or some other bogus address as your MailMessage.FromProperty. More advanced mail servers will catch this, and will deny relaying.

========================
I have no idea why this suggestion works, but I found it on the web. I figured I would mention it, just in case Suggestion 1 did not work. Instead of specifying
SmtpMail.SmtpServer = "127.0.0.1"
try
SmtpMail.SmtpServer.Insert( 0, "127.0.0.1 or your mail server name here")
0
 
zahabyCommented:
0
 
zahabyCommented:
thanks :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now