Value of type 'String' cannot be converted to 'System.Net.Mail.MailAddress'

My code is below:

Protected Sub btnSendMsg_OnClick(ByVal Source As Object, ByVal E As EventArgs)
Dim myMessage As New System.Net.Mail.MailMessage
Dim myAttachment As System.Net.Mail.Attachment
Dim myMail As System.Net.Mail.SmtpClient

If Page.IsValid() Then
myMessage.From = txtFromEmail.Text
myMessage.To = txtToEmail.Text


What can I do to fix this?
1
cheatcountry
5/10/2007 1:52:35 AM
asp.net.web-forms 93655 articles. 4 followers. Follow

11 Replies
3155 Views

Similar Articles

[PageSpeed] 36

MailMessage.To represents a collection that you Add addresses to.

Dim  recipient As MailAddress= new MailAddress(txtToEmail.Text)
myMessage.To.Add(recipient)

 

 


Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
5/10/2007 2:18:49 AM
Well I'm also having a problem with the From field.  What do I change that to?
0
cheatcountry
5/10/2007 2:30:57 AM

like this:

myMessage.From = New MailAddress(txtFromEmail.Text)
 
Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
5/10/2007 2:43:26 AM
thank you
0
cheatcountry
5/10/2007 2:46:54 AM

I am getting an error also my code is

Try

'Creates E-Mail

With objEmailMessage

.To = toAddress

.From = txtEmail.Text

.Subject = "Website Contact Form Submission"

.BodyFormat = System.Net.Mail.MailMessage.IsBodyHtml

.Priority = Net.Mail.MailPriority.High

.Body = body

End With

0
abetha
6/27/2007 1:18:24 PM

have you tried the same changes to the .To and the .From properties that i had suggested in the previous posts?

 


Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
6/28/2007 1:45:10 AM

I switched from Visual Studio 2003 to 2005.  I did try the change for .From but it is not working for me.

0
abetha
6/28/2007 5:14:44 PM

please post your updated code sample so we may see how you have implemented the suggested changes.

 


Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
6/28/2007 11:37:06 PM
Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click 

Dim strSMTPServer As String = System.Configuration.ConfigurationManager.AppSettings ("smtpserver") 'Sets SMTP server name

Dim objEmailMessage As New System.Net.Mail.MailMessage 'Sets email message object

Dim objSMTPServer As System.Net.Mail.SmtpClient 'Sets smtp server object

Dim toAddress As String 'To E-Mail address

Dim body As String = "" 'E-Mail body

Dim recipient As MailAddress = New MailAddress(txtFromEmail.Text)

 

Try

'Creates E-Mail

With objEmailMessage

.To = toAddress

objEmailMessage.From =
New MailAddress(txtFromEmail.Text)

.Subject = "Website Contact Form Submission"

.BodyFormat = System.Net.Mail.MailMessage

.Priority = Net.Mail.MailPriority.High

.Body = body

End With

0
abetha
6/29/2007 1:44:34 PM

You also need to change how you are accessing the .To property.  The .To property represents a collection of MailAddress objects.  You cannot assign a string to this property.

Dim  recipient As MailAddress= new MailAddress("somebody@somewhere.com")
objEmailMessage.To.Add(recipient)


Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
6/29/2007 4:16:07 PM

I have changed .To Property to .To.Add(toAddress)

0
abetha
6/29/2007 6:20:31 PM
Reply:

Similar Artilces:

System.Net.Mail is giving error CS0029: Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
I'm getting an error while trying to use the wizard to create a form and than pass it the vaibles to Mail. Any help would be much appreciated. SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try {   message.From = txtEmail.Text; message.To.Add("admin1@yoursite.com"); message.Subject = "Feedback"; message.CC.Add("admin1@yoursite.com"); message.CC.Add("admin2@yoursite.com"); message.IsBodyHtml = false; message.Body = txtMessage.Text; smtpClient.Send(message); lblStatus.Text = "Email successfully sent."; } catch (Exception ex) { lbl...

Value of type 'System.Net.Mail.MailMessage' cannot be converted to 'System.Net.Mail.AlternateView'
Trying to create an alternateview to send a txt email with the html formatted email.  I've used string builder to create the whole email, but I get this error.  Any ideas why?  i've bolded the line that throws the error... Dim EmailBodyTxt As New StringBuilder EmailBodyTxt.Append("<html><style type='text/css'>.table{border:solid; border-color:#006666; width:600;} ")EmailBodyTxt.Append("<body><table class='table'><tr><td colspan='2'><h1>Test<br />RESPONSE SYSTEM</h1></td>...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

Value of type 'System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap'.
 Hello,         I receive this error "System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap" when I try to find the Sitemap control.  ...            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />            <asp:ListView ID="ListView1" runat="server">            <LayoutTemplate>    ...

Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.TextBox'
I have a new page (wireframe) based on the User_Create page in the Time Tracker starter kit.  I have no code in the code behind page.  What might be causing this error?  This newbie needs help. I had a TextBox control named "Title" which appearantly conflicted with the page title. thanks!!! ...

Cannot convert value of parameter 'Course_FK' from 'System.String' to 'System.Guid'
Hi, I'm building a site and I've been trying to accomplish something similar to what is talked about in "Working with Data in ASP.NET 2.0 :: Declarative Parameters" tutorial. Below is the code for my methods from the xsd. I tried to attach a screenshot of my xsd but for some reason I'm not allowed GetAllCourseNames() SELECT        CourseID, NameFROM            Course GetCourseScheduleByCourseID SELECT        ScheduleID, Course_FK, Date, TeeTime, NumberOfPlayersF...

BC30311: Value of type 'System.Web.UI.WebControls.RadioButtonList' cannot be converted to 'String'.
I have a listview that I'm working with.  Each record returned by my sql query is displayed in my list view as text, with the exception of one field, which I need to display as a radiobutton list.  I tried to set the value of the radiobutton in my codebehind, but keep getting errors.  How do I tell this radiobutton list that the value that should be selected when the page loads is equal to the value returned from my sql query?    The line in bold throws the error... How am I supposed to indicate what value to have selected when the page loads? <asp:Radi...

BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'.
I have a pretty basic vb.net page that includes a listview.  (Note, this is my first time working with listview, so I may have some of the terminology wrong).  In my list view, I display all the important data for each record, and ask the user to provide a status for each record by including a radiobutton list with various responses.  At the bottom of the page is one submit button, and when the user clicks submit, I'm saving each records value based upon which response is selected in the radiobutton list. My saving of data is working,  but I'm ...

BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.TextBox'.
 Hello everyone, I receive the error in the subject when viewing this page, I can get it to work fine without the master page and only the textboxes, but that causes an error with line 11, even when the page contents do process to the form. I don`t understand the error and I would appreciate any guidance on this. Thanks for reading.1 <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %> 2 3 <script runat="server"> 4 5 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) 6 Dim D...

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

Having an error: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'.
Error Message: Compiler Error Message: BC30311: Value of type 'String' cannot be converted to 'System.Web.UI.WebControls.Label'. Line 13: myGetRandom.RetrieveDetails(lblQuestion.text, lblAnswers.text, lblViewCount.text, lblLastUpdated.text) Sub Page_Load Dim myGetRandom as new GetRandom myGetRandom.RetrieveDetails(lblQuestion.text, lblAnswers.text, lblViewCount.text, lblLastUpdated.text) End Sub Code behind Sub RetrieveDetails(lblQuestion as label, _ lblAnswers as label, _ lblViewCount as label, _ lblLastUpdated as...

Value of type 'System.IO.DirectoryInfo' cannot be converted to 'String'.
I am uploading documents, and have a basic multiple file upload (from the .NET tutorial) working great.  BUT, instead of putting all the files uploaded via the webpage, I want to put them in sub folders.  So,  I want each file to go in the C:\ directory, in a folder named Uploaded Files, and then, a sub folder with the number of a hiddenfield that is hdn.MatterID...   Here's what I tried, but am getting the error,  Value of type 'System.IO.DirectoryInfo' cannot be converted to 'String'code behind Protected Sub btnSubmit_Click(ByVal sen...

Value of type 'System.Data.Dataset' cannot be converted to 'String'
I receive the above error for line 57 which is: Address.text = Clientinfo(DropDownlist1.Items(DropDownList1.SelectedIndex).text) I'm trying to take the selected item from the dropdownlist1 and have the data from the query 'Clientinfo' appear using the label control called 'address'. I plan to format it to be used as a mailing address: 123 Street City, State Zip Etc. Obviously I am learning as I go. Can anyone give me an alternative or find my error. Much appreciated. The code is below: Sub Page_Load(Sender As Object, E As EventArgs) If Not Page.IsPostBa...

Value of type 'String' cannot be converted to 'System.Drawing.Color'
I have a user control for logging into a site. I place the user control on a page and in code behind set the color of the lables in the user control as such Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here UsernameLabel.ForeColor = "White" End Sub The problem I'm having is the error in the subject. I want to be able to change the font color of the label depending on the page it's placed on. Ideas? Should be: UsernameLabel.ForeColor=Syst...

Web resources about - Value of type 'String' cannot be converted to 'System.Net.Mail.MailAddress' - asp.net.web-forms

Resources last updated: 1/4/2016 6:46:36 PM