Sending Email using System.net.mail  
Author Message
Ramesh_Kumar_02a072





PostPosted: .NET Framework Networking and Communication, Sending Email using System.net.mail Top

hi everyone,

I have trouble to send email using system.net.mail in ASP.NET 2.0 with VB

here is my code.... any body tell me what is going wrong with the code.

Code for SendEmail.vb

Imports Microsoft.VisualBasic

Imports System.Net.Mail

Public Class SendEmail

Public Sub SendEmailMessage(ByVal fromMail As String, ByVal toMail _

As String, ByVal subjectMail As String, ByVal messageMail As String)

'This procedure takes four string parameters for sending the mail

Try

'address create a mail message

Dim MailMsg As New MailMessage(New MailAddress(fromMail.Trim()), New MailAddress(toMail))

MailMsg.BodyEncoding = Encoding.Default

MailMsg.Subject = subjectMail

MailMsg.Body = messageMail.Trim() & vbCrLf

MailMsg.IsBodyHtml = True

MailMsg.Priority = MailPriority.High

'Smtpclient to send the mail message

Dim SmtpMail As New SmtpClient

SmtpMail.Host = "59.89.122.86" 'IP address of my computer system

SmtpMail.Send(MailMsg)

'Message Successful

Catch ex As Exception

MsgBox("Failed")

'Message Error

End Try

End Sub

End Class

============================================================

Code for Default.aspx.vb

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim SendEmail As New SendEmail

Dim SendTo As String = TextBox1.Text

Dim strSubject As String = TextBox2.Text

Dim strMessage As String = TextBox3.Text

SendEmail.SendEmailMessage( , SendTo, strSubject, strMessage)

End Sub

End Class

======================================================================

waiting for response....




.NET Development8  
 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, Sending Email using System.net.mail Top

Can you post your error What error are you getting when you run the code

Best Regards,

Rizwan aka RizwanSharp



 
 
Brendan Grant





PostPosted: .NET Framework Networking and Communication, Sending Email using System.net.mail Top

So we’ve got the code and the knowledge that there is a problem... but what is that problem How is it failing Are you getting any errors If so, what are they Do you have a working SMTP server up and running at the specified address

If you are getting an exception, you might want to examine the actual exception being returned for more details.



 
 
Ramesh Kumar





PostPosted: .NET Framework Networking and Communication, Sending Email using System.net.mail Top

Yes, I have a working SMTP server and ruuning at the specified address.

I m not getting an error messge but also it returns exception......................

with msgbox("Failed")



 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, Sending Email using System.net.mail Top

Yes tell us complete exception with stack trace to let us know what is the problem.

Best Regards,

Rizwan aka RizwanSharp



 
 
Ramesh Kumar





PostPosted: .NET Framework Networking and Communication, Sending Email using System.net.mail Top

I can't able to get the actual exception. I m trying to convert the exception to string and

it diplays System.Exception cannot be converted to type 'String'



 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, Sending Email using System.net.mail Top

I can't able to get the actual exception. I m trying to convert the exception to string and

it diplays System.Exception cannot be converted to type 'String'

Put a Try/Catch around the code which is giving error

and see Message property of exception, It'll give you the reason for that exception.

Best Regards,

Rizwan aka RizwanSharp



 
 
Ramesh Kumar





PostPosted: .NET Framework Networking and Communication, Sending Email using System.net.mail Top

Excaption :MailBox unavailable, The Server response was:5.7.1 unable to relay for

where is my valid e-mail address(id)



 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, Sending Email using System.net.mail Top

OK Good to know the message:

Seee this:

http://codebetter.com/blogs/peter.van.ooijen/archive/2006/04/05/142331.aspx

I hope this will solve your problem.

Best regards,

Rizwan aka RizwanSharp



 
 
Ramesh Kumar





PostPosted: .NET Framework Networking and Communication, Sending Email using System.net.mail Top

OK Good to know the message:

Seee this:

http://codebetter.com/blogs/peter.van.ooijen/archive/2006/04/05/142331.aspx

I hope this will solve your problem.

Best regards,

Rizwan aka RizwanSharp

Yes, U are right.

Thanks a lot to solve my problem.......