erum mirza

erum mirza

  • NA
  • 429
  • 0

how to mail from asp.net 3.5

Jan 6 2011 1:35 AM

i have following code in asp.net 3.5 to mail send from admin
 
 

Public
Sub EmailToclient(ByVal email As String, ByVal username As String, ByVal password As String)
' Try
Dim mail As New MailMessage()
'mail.[To].Add("[email protected]")
mail.[To].Add(email)
' mail.From = New MailAddress("[email protected]")
mail.From =
New MailAddress(System.Configuration.ConfigurationManager.AppSettings("From").ToString())
Dim NetworkCred As New System.Net.NetworkCredential()
NetworkCred.UserName =
"[email protected]"
NetworkCred.Password =
"Admin"

' or could be @gmail.com and etc OR it can be a textbox were you CAN enter your email
' mail.Subject = "Comment/Question"
mail.Subject = System.Configuration.ConfigurationManager.AppSettings(
"EmailSubject").ToString()


'string Body = the_textbox_Name_were_you_enter_your_message.text;
' Dim Body As [String] = "body text"
mail.Body =
"Dear " & username & " your password is " & password
mail.IsBodyHtml =
True
Dim smtp As New SmtpClient()
'smtp.Host = "smtp.gmail.com"
'smtp.Host = "174.133.41.130"
smtp.Host =
"mail.gfln.org"
'smtp.Port = 587
smtp.Port = 25
'smtp.Credentials = New System.Net.NetworkCredential(email, "Admin")

smtp.UseDefaultCredentials =
True
smtp.Credentials = NetworkCred


smtp.EnableSsl =
True
smtp.Send(mail)
' Catch ex As Exception
' Throw ex
' End Try
End Sub
 

 
Failure sending mail.

System.Net.Mail.SmtpException was unhandled by user code
Message="Failure sending mail."
Source="System"
StackTrace:
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at gfln1.ViewCompany1.Button1_Click(Object sender, EventArgs e) in C:\Users\Iram\Documents\Visual Studio 2008\Projects\gfln1\gfln1\ViewCompany1.aspx.vb:line 108
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: System.Net.WebException
Message="Unable to connect to the remote server"
Source="System"
StackTrace:
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
InnerException: System.Net.Sockets.SocketException
ErrorCode=10061
Message="No connection could be made because the target machine actively refused it 2001:0:4137:9e76:3808:bd63:4b4d:74f7:25"
NativeErrorCode=10061
Source="System"
StackTrace:
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
InnerException:

Answers (7)