Solved

Problem in sending the email

Posted on 2009-05-17
9
173 Views
Last Modified: 2013-12-17
Hi

I am using the following code to send an email

But I am getting runtime error

Can you please tell me the reason
MailMessage message = new MailMessage();
        message.From = new MailAddress("sender@domain.com");
        message.To.Add(new MailAddress(MailTo));
        message.Subject = Subject;
        message.Body = Body.ToString();
        
        SmtpClient client = new SmtpClient("localhost");                       
        client.EnableSsl = true;
        client.Send(message);

Open in new window

0
Comment
Question by:KaranGupta
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 24409109
put tje valid mail address  here

message.From = new MailAddress("sender@domain.com");

What error you are getting ?
0
 

Author Comment

by:KaranGupta
ID: 24409119
Hi

I have changed it to valid email id

But I am getting the same error

"Failure sending mail. "
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24409137
Is the machine you are running the code on (localhost) an SMTP server?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:KaranGupta
ID: 24409139
No

I think we are using the the SMTP service in services.msc to send an email
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 250 total points
ID: 24409142
message.From.Add(new MailAddress("sender@domain.com"));
        message.To.Add(new MailAddress(MailTo));


also try hard coded values

client.Send("to","Form","subject","body");
also cj=heck your localhost is confogured for SMTP or not ?
0
 

Author Comment

by:KaranGupta
ID: 24409144
I have an outlook configured on my machine

so I think my machine also configures for SMTP
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24409174
Does your Outlook go to localhost as well? If not, the copy the server address that Outlook is using into your

    SmtpClient client = new SmtpClient("server_name_here");

line.
0
 

Author Comment

by:KaranGupta
ID: 24409239
Hi

SmtpClient client = new SmtpClient()

with this I want to use gmails smtp server

How can I specify here
0
 
LVL 9

Assisted Solution

by:tetorvik
tetorvik earned 250 total points
ID: 24409295
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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