Solved

Problem in sending the email

Posted on 2009-05-17
9
168 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 74

Expert Comment

by:käµfm³d 👽
ID: 24409137
Is the machine you are running the code on (localhost) an SMTP server?
0
 

Author Comment

by:KaranGupta
ID: 24409139
No

I think we are using the the SMTP service in services.msc to send an email
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 74

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

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

Suggested Solutions

Title # Comments Views Activity
comparing string in C# 3 34
Round a string to two digits 12 25
C# Application Local DB Connection String 23 61
cs.Designer Issue 2 20
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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

11 Experts available now in Live!

Get 1:1 Help Now