?
Solved

Problem in sending the email

Posted on 2009-05-17
9
Medium Priority
?
185 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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 1000 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 1000 total points
ID: 24409295
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

840 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