Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2010, 02:45 AM
Registered User
 
Join Date: May 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default MailMessage

Hi all

Iam trying to code my Email web form to enable it to send emails . The code seems correct except that I get an error when declaring mailMessage
as in Dim MM as MailMessage

MailMessage is underlined and Iam getting an error saying "MailMessage is ambigious" and something about a namespace. Here is my code below please assist?

Imports System
Imports System.Web.Mail
Imports System.Net.Mail
Imports System.Net
Imports Microsoft.SqlServer
Imports System.Net.Mail.MailMessage
Imports System.Data.SqlClient
Imports System.Web.Profile
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.IO
Imports System.Net.Mail.SmtpClient

Partial Class Email
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim MySmtpClient As New SmtpClient
Dim MM As New MailMessage()
MySmtpClient.Host = "Tinashe -pc."
MySmtpClient.Port = 25
'Dim fromAddress As New MailAddress '(" [email protected]","Tinahse ")
MM.From = TextBox1.Text
MM.To = "[email protected]"
'you also can set this to TextBox2.Text
MM.Cc = TextBox3.Text
MM.Bcc = TextBox4.Text
MM.Subject = TextBox5.Text
MM.BodyFormat = TextBox7.Text
MM.Body = TextBox6.Text
'textbox6 TextMode property is set to MultiLine
MM.Priority = MailPriority.Normal
MySmtpClient.SmtpServer = "mail.tinashe-pc.com"
'mail server used to send this email. modify this line based on your mail server
MySmtpClient.Send(MM)
Label6.Text = "Your mail was sent"
'message stating the mail is sent


End Sub
End Class
 
Old August 31st, 2010, 03:30 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You're importing both the old (System.Web) and the new (System.Net) Mail namespaces. Both namespaces contain the MailMessage class. Simply remove

Imports System.Web.Mail

and the "MailMessage is ambigious" error should go away.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 1st, 2010, 06:09 PM
Registered User
 
Join Date: May 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar

Thanks for that I managed to solve the MailMessage error , but now I am getting an error that following erros after making that change


Error 1 Value of type 'String' cannot be converted to 'System.Net.Mail.MailAddress'.
Property 'To' is readOnly
Property 'CC' is readOnly
Error 5 'BodyFormat' is not a member of 'System.Net.Mail.MailMessage'.
 
Old September 2nd, 2010, 02:12 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Not only the namespace changed, but the API as well. So for example, To is no longer a simple field, but a collection now. That means you can't assign strings, you now need to add MailAddress instances.

Check out this site for lots of examples: http://www.systemnetmail.com/

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
SmtpClient MailMessage .NET 2.0 ddudley3 C# 2005 0 February 23rd, 2006 04:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.