Connecting Tech Pros Worldwide Forums | Help | Site Map

How to send mail on yahoo, hotmail

Member
 
Join Date: Feb 2007
Posts: 53
#1: Jul 8 '09
Hello All,

I want to send mail through asp.net to other my company domain e.g yahoo, hotmail etc
Code is as below

////Start Code////////
Expand|Select|Wrap|Line Numbers
  1. Imports System.Net.Mail
  2.  Dim MailMessage As MailMessage = New MailMessage
  3.  
  4.         MailMessage.From = New System.Net.Mail.MailAddress   ("DO_NOT_REPLY@QHSE.COM")
  5.  
  6.         MailMessage.To.Add(New MailAddress("abc@hotmail.com"))
  7.  
  8.         MailMessage.Subject = "Subject"
  9.  
  10.         MailMessage.Body = "Body"
  11.  
  12.         Dim SmtpClient As SmtpClient = New SmtpClient
  13.  
  14.         SmtpClient.Host = "es10" ' my email server
  15.         SmtpClient.Port = 25
  16.  
  17.         Try
  18.             SmtpClient.Send(MailMessage)
  19.  
  20.         Catch ex As Exception
  21.             Response.Write(ex.Message)
  22.         End Try
////////////End Code///

But it returns error message as below.

Transaction failed. The server response was: Relay rejected for policy reasons.

Note: when i send email to my company adress through this code it work properly.

Any one can help

Thanks

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,719
#2: Jul 8 '09

re: How to send mail on yahoo, hotmail


Is your mail server configured to allow outbound emails?
insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,695
#3: Jul 9 '09

re: How to send mail on yahoo, hotmail


I don't believe that Hotmail or Yahoo will let you use their relays.

You might try providing your login credentials to the SMTP server though. It may work.

Before I give you this code sample, I have to say that using a Class name for an instance name is just plain crazy. You made an SmtpClient object called SmtpClient. How do you know which you are referring to, the instance, or the class? Change the name to something else, like this maybe:

Expand|Select|Wrap|Line Numbers
  1. Dim MailServer As SmtpClient = New SmtpClient
  2. MailServer.Credentials = new System.Net.NetworkCredential("username", "password")
Reply