Solved

Problem in sending the email

Posted on 2009-05-17
9
171 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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

773 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