0

i tried to send simple mail in asp.net.it doesn't work.

Here is code:

protected void Button2_Click(object sender, EventArgs e)
{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gorenparmak.com");
    mail.From = new MailAddress("radyo@gorenparmak.com");
    mail.To.Add("radyo@gorenparmak.org");
    mail.Subject = "Test Mail - 1";
    mail.Body = "mail with attachment";

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("radyo@gorenparmak.com", "write password");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);
}

Error produced when I run it:

The remote name could not be resolved: 'smtp.gorenparmak.com'

How I can solve this problem?

Richard
  • 29,854
  • 11
  • 77
  • 120
OPETH
  • 1
  • 3
  • It seems like DNS problem. First, is this domain bought or configured via hosts (for example)? – Rolice Oct 21 '12 at 10:28
  • Have you tried using the IP address rather than the DNS name? – Kane Oct 21 '12 at 10:30
  • Try pinging the smtp.gorenparmak.com and see if you can connect with the remote server. – Usman Khalid Oct 21 '12 at 10:33
  • You may want to consider encapsulating that email functionality into it's own method. Maybe something fancy, like "SendEmail()". Maybe paramterize it so it'll work for any email address, to and from. Something like that. =) – Yatrix Oct 21 '12 at 10:33
  • As a FYI `smtp.gorenparmak.com` does not resolve using my internet provider (iiNet in Australia) – Kane Oct 21 '12 at 10:35
  • It doesn't resolve in Denmark either. Use the IP address or specify it in the servers host file. – faester Oct 21 '12 at 10:41
  • Should i contact hosting firm? – OPETH Oct 21 '12 at 11:00
  • Can i solve this problem if i use smtp.gmail.com? – OPETH Oct 21 '12 at 11:12
  • Yes you can use gmail client to send email but you will need gmail account. Refer - http://stackoverflow.com/a/1312095/158207 – Parag Meshram Oct 21 '12 at 12:27

1 Answers1

0

Try to use PORT 25 as PORT 587 is used for gmail

Example try below to see if it work otherwise you have issue with DNS

 // Set the to and from addresses.
 // The from address must be your GMail account
 mail.From = new MailAddress("gorenparmak.net<radyo@gorenparmak.com>");
 mail.To.Add(new MailAddress(to));

 // Define the message
 mail.Subject = subject;
 mail.IsBodyHtml = isHtml;
 mail.Body = message;

 // Create a new Smpt Client using Google's servers
 var mailclient = new SmtpClient();
 //mailclient.Host = "smtp.gmail.com";//ForGmail
 mailclient.Host = "mail.gorenparmak.com";
 //mailclient.Port = 587; //ForGmail
 mailclient.Port = 25;

 // This is the critical part, you must enable SSL
 //mailclient.EnableSsl = true;//ForGmail
 mailclient.EnableSsl = false;
 mailclient.UseDefaultCredentials = true;

 // Specify your authentication details
 //mailclient.Credentials = new System.Net.NetworkCredential("SomeGmailAccount@gmail.com", "PaswordXYX123");//ForGmail
 mailclient.Credentials = new System.Net.NetworkCredential("noreply@gorenparmak.com", "PaSsWaRd");

 mailclient.Send(mail);
 mailclient.Dispose();
Learning
  • 19,469
  • 39
  • 180
  • 373