Asked by:
ASP.Net 2005 - How To Send Email

Question
-
'My Code For Send Email .................
-----------------------------------------------------------------------------------------------------------------Public Sub send_email(ByVal mTo As String, ByVal mFrom As String, ByVal mCc As String, ByVal mBody As String)
mMailServer = "localhost"
' ConfigurationManager.AppSettings.Get("MyMailServer")
mPort = 25
'mPort = ConfigurationManager.AppSettings.Get("MyMailServerPort")Try
Dim message As New MailMessage(mFrom, mTo, mSub, mBody)If upload_file.HasFile Then
Dim attached As New Attachment(Trim(upload_file.PostedFile.FileName.ToString))
message.Attachments.Add(attached)
End If'If mCc <> "" Or mCc <> String.Empty Then
' Dim strCc() As String = Split(mCc, ";")
' Dim this_string As String
' For Each this_string In strCc
' message.CC.Add(Trim(this_string))
' Next'End If
'message.DeliveryNotificationOptions = 2
'Dim my_wholeMessage As New SmtpClient("127.0.0.1", mPort)
my_wholeMessage.UseDefaultCredentials = True
my_wholeMessage.Send(message)Catch ex As FormatException
lbl_error.Text = "Please fill required parameters for send Email : " & ex.MessageCatch ex As SmtpException
lbl_error.Text = "Error during SMTP mail transfer : " & ex.MessageCatch ex As Exception
lbl_error.Text = "Email not sent successfully server not found : " & ex.Message
End Try
End Sub
----------------------------------------------------------------------------------------'-------------------------------------
Web.config file ...........
----------------------------------------
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network port="25" defaultCredentials="true" host="localhost"/>
</smtp>
</mailSettings>
</system.net>
-------------------------------------------------------From above code i am not able to send message .....
Tell me the wats wrong with above code
Monday, April 7, 2008 9:20 AM
All replies
-
Your code looks correct. What error messages or exceptions do you get?
You should be getting some exception at "my_wholeMessage.Send(message)". Most likely, you do not have a SMTP service running. You might also want to check up on your firewall settings and make sure port 25 is unblocked.
Wednesday, April 23, 2008 9:48 AM -
You may check whether these settings are applied in your machine.
Ref Link - http://www.geekzilla.co.uk/View26D8B20C-4627-432D-9664-63AC43EAFDF8.htm
Also please go through this article - http://www.codeproject.com/KB/aspnet/EmailApplication.aspx
Tuesday, June 3, 2008 5:57 AM -
Is this a problem sending all emails or ones with attachments? It's a little difficult to help without knowing what error you are getting.
You are probably going to have problems if you have attachments because of this section:
Dim attached As New Attachment(Trim(upload_file.PostedFile.FileName.ToString))
message.Attachments.Add(attached)You need to save the attachement to disk first. Simply attaching a file by name won't work in this context, because that is simply the name of the file from the client.
Monday, June 7, 2010 12:29 PM