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)

{

lblStatus.Text =

"Send Email Failed." + ex.Message;

}

}

}

0
prosenba
12/14/2006 11:25:41 PM
asp.net.web-forms 93655 articles. 3 followers. Follow

3 Replies
1885 Views

Similar Articles

[PageSpeed] 58

Hi, message.From property is of MailAddress type, so you have to assign it this way:
message.From = new System.Net.Mail.MailAddress(txtEmail.Text);
Hope it helps.
0
raymond
12/15/2006 3:42:04 AM
0
jessjing
12/15/2006 4:52:32 AM

Check this link http://www.systemnetmail.com

Thanks 


Mark post(s) as "Answer" that helped you

Electronic Screw
Website||Blog||Dub@i.net
0
e_screw
12/15/2006 9:11:26 AM
Reply:

Similar Artilces:

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>...

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.TextWhat can I do to fix this? MailMessage.To represents a collection that you Add addresses to.Dim recipient As MailAddress= new MailAddress(txtToEmail.Text) myMessage.To.Add(recipient)    Mike Banavige~~~~~~~~~~...

CS0029: Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.DropDownList'
I've got another error. Don't know where this is coming from. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.DropDownList'Source Error: Line 1: <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="add_contact2.as...

Error: Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField'
Hello, I am getting the following error during compiliation. Any suggestions to fix it. Thanks. Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField' protected void gvEvents_RowCommand(Object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvEvents.Rows[index]; string sID; ButtonField btn; if (selectedRow.RowType == DataControlRowType.DataRow) { sID = ((ButtonField)selectedRow.FindControl("ID")).DataTextFi...

Convert 'System.DBNull' to type 'System.String' ?
I have a textbox on my site that I want to populate with some data, however when the value is null, which is quite often.The problem is that when I call a static method which returns a string; when that string is DBNull, I get the following error which is absolutely correct.Unable to cast object of type 'System.DBNull' to type 'System.String'.So, what should I do to be able to ignore that the string is null and just display a "" string in the texbox?The code is as follows:    private void GetCartSmall(string sSessionID)    {      &n...

Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string'
I have a datagridLabel ID1 = (Label)(e.Item.FindControl("ID1")); Label Name1 = (Label)(e.Item.FindControl("Name1")); Label TableName = (Label)(e.Item.FindControl("TableName"));   No0w Iam trying to TBTableName.Text = lblTableName;                  tbid.Text = lblImageTypeID1;                   tbnameordes.Text = lblImageName1; I have tried l lbltablename.text,.tostring,convert.t...

Cannot implicitely convert type 'string' to 'System.Web.UI.WebControls.Label'
 I'm starting to make a website for users to login. Once they login, I'm showing their profile. So I populate some asp:label controls on Page_Load. My profile page (shown after the user logs in) contains: <%@ Page Language="C#" MasterPageFile="~/site.master" CodeFile="clientProfile.aspx.cs" Inherits="clientProfile" AutoEventWireup="true" Title="Car Look - Your profile" %> <asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server"> <div> &l...

ASPNET2 HELP! CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'.
Server Error in '/start-movieposters' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'. An explicit conversion exists (are you missing a cast?) Source Error: ...

Object of type 'System.DBNull' cannot be converted to type 'System.String' from formview
I have a formview that I am using for input to my datatable.  I am using an objectdatasource that uses a BLL.  This in turn points to my XSD tableadapter. When I test, and only fill in the required fields, I am getting the error Object of type 'System.DBNull' cannot be converted to type 'System.String' I am not sure what field is having the issue.  In my BLL for the Add, I have checked the dates for null and placed the value of DateTime.MinValue.  For the text fields, I have place "" if they are null.  Is this error being create prior to...

Error
Hi Friends, I am trying to limit the width of ImageButton control not to exceed 120 pixels. But neither of the code snippets below work. Any suggestions? // ------------------------ int iWidth = 120; if (this.ImageButton1.Width > Unit.Parse(iWidth.ToString())) { this.ImageButton1.Width = 120; } // ------------------------ if (this.ImageButton1.Width > 120) { this.ImageButton1.Width = 120; } // ------------------------ Thank you in advance for your feedback. Rajan this.ImageButton1.Width is of datatype "unit" where a...

Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string' #2
Hi i am getting the following error "Cannot implicitly convert type 'System.Web.UI.WebControls.Label' to 'string'", what am i doing wrong, my code looks like this;protected void lbtnSubmit_Click(object sender, EventArgs e) {foreach(DataGridItem dgi in dgAvailability.Items) {AvailabilityBLC availabilityBLC = new AvailabilityBLC(); availabilityBLC.Availability.AvailabilityDay =(Label)dgi.FindControl("lblDay");availabilityBLC.Availability.AvailabilityPrice = (TextBox)dgi.FindControl("priceTxt"); availabilityBLC.Availability.BBooked = (CheckB...

Cannot implicitly convert type 'string' to 'System.DateTime'
Hi, I have a DateTime field in my sql server database. The field can take null value. In my aspx page, i have a textbox to get the input from the user. If the textbox value is empty, how to handle it? This is my cs code: objMyTime.StartTime = DateTime.Parse(txtStartTime.Text);   I am getting error as: "Cannot implicitly convert type 'string' to 'System.DateTime' " Thank you  seems to me objMyTime.StartTime is a string and ur trying to assign the datetime.try with this objMyTime.StartTime = DateTime.Parse(txtStartTime.Text).ToString();use RequiredFi...

Cannot implicitly convert type 'System.DBNull' to 'System.DateTime'
I'm using _StartDate = DBNull.Value;  _StartDate is datetime Somehow its not working when I set to dbnull.value Error 1 Cannot implicitly convert type 'System.DBNull' to 'System.DateTime'   i want to set to null or empty, how do i do that?  thanks.Its all about coding! Dear, the DateTime datatype cannot be null. that is why ur getting this kind of error what u can do is to set the default value for the DateTime variable that u have to the DateTime.MinValue. it will give u a date (1/1/0001) which for sure you can depend on. Happy codingHaissam Abdul MalakMCA...

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...

Web resources about - System.Net.Mail is giving error CS0029: Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress' - asp.net.web-forms

Resources last updated: 2/2/2016 11:54:04 PM