Link to home
Start Free TrialLog in
Avatar of KaranGupta
KaranGupta

asked on

Problem in sending the email

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

Avatar of Pratima
Pratima
Flag of India image

put tje valid mail address  here

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

What error you are getting ?
Avatar of KaranGupta
KaranGupta

ASKER

Hi

I have changed it to valid email id

But I am getting the same error

"Failure sending mail. "
Is the machine you are running the code on (localhost) an SMTP server?
No

I think we are using the the SMTP service in services.msc to send an email
ASKER CERTIFIED SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have an outlook configured on my machine

so I think my machine also configures for SMTP
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.
Hi

SmtpClient client = new SmtpClient()

with this I want to use gmails smtp server

How can I specify here
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial