School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
You're Browsing As A Guest! Register Now...
Become an Expert!

Join 358,764 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,781 people online right now.Registration is fast and FREE... Join Now!



Web Mails asp.net

52 Weeks of Code Challenge: Android

Week #11 of the 52 Weeks of Code Challenge is Android, you should give it a shot. Click Here!

Web Mails asp.net Rate Topic: -----

#1 Pablo3728  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 13-October 09


Dream Kudos: 0

Post icon  Posted 30 October 2009 - 06:07 AM

Hello! Well I am doing a web Application en asp.net using vb.net. (vs 2005) I have a code to send mails in this web application, but I think that this code is from an older version, becouse I have warnings that say the next:

'System.Web.Mail.MailMessage' is obsolete: 'The recommended alternative is System.Net.Mail.MailMessage.

I really don´t know how to use System.Net.Mail.MailMessage, If somebody has an idea or a helpful page would be great.

THis is my code:
(I will put in brackets the word "here" to show where the warning appear)

 Public Shared Function MandarMensaje(ByVal from As String, ByVal para As  String, ByVal subject As String, ByVal body As String) As String
		Dim mail As MailMessage (Here)
		Dim serv As String

		mail = New MailMessage(here)
		mail.From = from
		mail.To = para
		mail.Bcc = "alopeza@evimed.net"
		mail.Subject = subject
		mail.Body = body
		mail.BodyFormat = MailFormat.Html (here)

		Try
			serv = "10.100.11.112"
			If serv <> "" Then
				SmtpMail.SmtpServer = serv (here)
			End If
			SmtpMail.Send(mail) (here)
			Return "OK"
		Catch ex As Exception
			Return "Se produjo un error al enviar el mensaje. Intente más tarde."
		Finally
		End Try

	End Function 



Thank you! :)
Was This Post Helpful? 0
  • +
  • -


#2 Jayman  Icon User is offline

  • Student of Life
  • Icon

Reputation: 298
  • View blog
  • Posts: 9,012
  • Joined: 26-December 05


Dream Kudos: 500

Expert In: Everything

Re: Web Mails asp.net

Posted 30 October 2009 - 06:52 AM

Check the following link for information on how to do it.

http://weblogs.asp.n.../16/432854.aspx
Was This Post Helpful? 0
  • +
  • -

#3 mb2000inc  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 2
  • View blog
  • Posts: 49
  • Joined: 10-November 09


Dream Kudos: 0

Re: Web Mails asp.net

Posted 11 November 2009 - 01:38 PM

Did you resolve this issue? I have some other (2005) code that can help, if you still haven't resolved it.

Please let me know and I'll post it for you.
Was This Post Helpful? 0
  • +
  • -

#4 Pablo3728  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 13-October 09


Dream Kudos: 0

Re: Web Mails asp.net

Posted 12 November 2009 - 04:18 AM

Hi! Thank you mb2000inc! Well, the program works ok, can send mails, but the warnings are there. If you have other code, would be great! :)
Was This Post Helpful? 0
  • +
  • -

#5 mb2000inc  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 2
  • View blog
  • Posts: 49
  • Joined: 10-November 09


Dream Kudos: 0

Re: Web Mails asp.net

Posted 12 November 2009 - 07:03 AM

View PostPablo3728, on 12 Nov, 2009 - 04:18 AM, said:

Hi! Thank you mb2000inc! Well, the program works ok, can send mails, but the warnings are there. If you have other code, would be great! :)


Let me first ask you, is this part of a contact form or is this an automated message that you're sending out to people or yourself for some purpose? The code I have is for a contact form. See below:
Imports System.Web.Mail
Imports System.EventArgs
Imports System.Object
Imports System.Web.UI.Control

Partial Class ContactUs
	Inherits System.Web.UI.Page

	Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
		Try

			'Declarations for variables
			Dim mailMessage As New System.Net.Mail.MailMessage
			Dim strToAddress, strFristName, strLastName, strPhone, strEmail, strState, strHowHearOfUs, strComments As String
		   
			'Assign values to your variables
			'Don't forget to change the "to address" - you can also assign this to a form control
			strToAddress = "youraddress@yourdomain.com"
			strFristName = txtFName.Text
			strLastName = txtLName.Text
			strEmail = txtEmail.Text
			strPhone = txtPhone.Text
			strState = dlState.SelectedValue
			strHowHearOfUs = dlHowHear.SelectedValue
			strComments = txtComments.Text

			'Create The To, From , And subject... then Encode the body formatting.
			mailMessage.From = New System.Net.Mail.MailAddress(strEmail.ToString)
			mailMessage.To.Add(strToAddress)
			mailMessage.Subject = "INSERT SUBJECT HERE ==> (X)"
			mailMessage.IsBodyHtml = True
			mailMessage.Body = ("<html><p><h2>The following person had filled out the request for contact form</h2></p><p>Their contact information is as follows: <br /><strong>First Name: </strong>" & strFName & "<br /><strong>Last Name: </strong>" & strLName & "<br /><strong>Email: </strong>" & _
			strEmail & "<br /><strong>Phone Number: </strong>" & strPhone & "<br /><strong>State: </strong>" & strState & "<br /><strong>How they heard of us: </strong>" & strHowHear & "<br /><strong>Comments: </strong><br />" & strComments & "<br /><br />Please review the information and contact them as soon as possible.</p></html>")

			'Send the Email
			'DON'T FORGET TO CHANGE THE MAIL SERVER ADDRESS BELOW
			Dim smtp As New System.Net.Mail.SmtpClient("PUT YOUR MAIL SERVER ADDRESS HERE")
			smtp.Send(mailMessage)
			Label8.Text = "Thank You.  Your mail has been sent"

			'Display a client-side popup, explaining that the email has been sent
			ClientScript.RegisterStartupScript(Me.GetType(), "PUT A NAME HERE", String.Format("alert('Your message has successfully been sent to {0}');", strToAddress.Replace("'", "\'")), True)

		Catch smtpEx As Net.Mail.SmtpException
			'A problem occurred when sending the email message
			ClientScript.RegisterStartupScript(Me.GetType(), "PUT A NAME HERE", String.Format("alert('There was a problem in sending the message: {0}');", smtpEx.Message.Replace("'", "\'")), True)

		Catch generalEx As Exception
			'Some other problem occurred
			ClientScript.RegisterStartupScript(Me.GetType(), "PUT A NAME HERE", String.Format("alert('There was a general problem: {0}');", generalEx.Message.Replace("'", "\'")), True)
		End Try
	End Sub
End Class


Was This Post Helpful? 1
  • +
  • -

#6 mb2000inc  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 2
  • View blog
  • Posts: 49
  • Joined: 10-November 09


Dream Kudos: 0

Re: Web Mails asp.net

Posted 16 November 2009 - 11:44 AM

I take it, this worked for you? :)

I have some other code that might be helpful if you're interested.
Like, sending emails with attachments.
Was This Post Helpful? 0
  • +
  • -

#7 Pablo3728  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 13-October 09


Dream Kudos: 0

Re: Web Mails asp.net

Posted 17 November 2009 - 06:10 AM

HI mb2000inc! Yes, the code works ok!! Thank you! I am interested in sending emails with attachments, would be great if you could give me the code. :)
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month