Send Email from form using system.net.mail

Please see code behind below.

This my message is being received by only with hard coded text of subject with no body.

 How do I correct my syntax so that the information is passed from form fields to email message?

 The form data is being inserted into the db and redirected to .aspx page.  Just need to get data from for fields to message.

 --------------------------------------------

Imports System.Net.Mail

Partial Class apps_contactpage

Inherits System.Web.UI.Page

Sub Send2Mail(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)

'create the mail message

Dim mail As New MailMessage()

Dim cName As String

Dim cEmail As String

Dim cPhone As String

Dim cBusiness As String

Dim cMessage As String

cName = Request.Form("cName")

cEmail = Request.Form("cEmail")

cPhone = Request.Form("cPhone")

cBusiness = Request.Form("cBusiness")

cMessage = Request.Form("cMessage")

'set the addresses

mail.From = New MailAddress("nobody@email.com")

mail.To.Add("nobody@email.com")

'set the content

mail.Subject = "Email Subject Test"

mail.Body = cName

mail.Body = cPhone

mail.Body = cBusiness

mail.Body = cMessage

'send the message

Dim smtp As New SmtpClient("mail.xxxxx.com")

smtp.Send(mail)

'redirect after data inserted to db

Response.Redirect("contactTest.aspx")

End Sub

End Class

 --------------------------------------------

Regards,

 TRU

0
TRU
1/13/2009 4:14:24 AM
asp.net.getting-started 91979 articles. 3 followers. Follow

10 Replies
760 Views

Similar Articles

[PageSpeed] 52

 mail.Body = "Name " & cName & "<br />"

mail.Body = mail.Body & "Phone " & cPhone & "<br />"

mail.Body = mail.Body & "Bussiness " cBusiness & "<br />"

mail.Body = mail.Body & "Message " & cMessage & "<br />"


We All move to our original place.
Don't forget.

Imran Baloch
0
imran_ku07
1/13/2009 4:58:53 AM

Try this:

mail.Body = cName & vbCrLf
mail.Body = mail.Body & cPhone & vbCrLf
mail.Body = mail.Body & cBusiness & vbCrLf
mail.Body = mail.Body & cMessage

I'm not sure if the vbCrLf field will work in this form or if it needs to be Constants.vbCrLf.

This presumes that you're using Text for your email.  If it's HTML, then you need "<br />" instead.


Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/13/2009 5:09:50 AM

imran_ku07:
 mail.Body = "Name " & cName & "<br />"

mail.Body = mail.Body & "Phone " & cPhone & "<br />"

mail.Body = mail.Body & "Bussiness " cBusiness & "<br />"

mail.Body = mail.Body & "Message " & cMessage & "<br />"

 

Returns....

 

Name <br />Phone <br />Bussiness <br />Message <br />

 

No values from form returned.

 

TRU

0
TRU
1/13/2009 5:58:21 AM

Careed:
mail.Body = cName & vbCrLf
mail.Body = mail.Body & cPhone & vbCrLf
mail.Body = mail.Body & cBusiness & vbCrLf
mail.Body = mail.Body & cMessage

 

Nothing returned in body of email message. Sad

TRU

0
TRU
1/13/2009 6:04:25 AM

Request.Form("cName") what is cName, is it a Label then this value is not Posted Back,
Why Not U are Using cName.Text.

Replace <br /> with Environment.NewLine


We All move to our original place.
Don't forget.

Imran Baloch
0
imran_ku07
1/13/2009 6:15:25 AM

cName is a textbox

0
TRU
1/13/2009 6:22:22 AM

apparently I am not requesting the values of the text fields from the form correctly.

 My code is a code behind dependent on the OnInsertedItem event of InsertButton

 Can you look at my requests?  Are these done correctly?

 TRU

0
TRU
1/13/2009 6:33:43 AM

Use this to get value 

 Dim cName As String=Ctype(FormView1.FindControl("cName"),TextBox)).Text


We All move to our original place.
Don't forget.

Imran Baloch
0
imran_ku07
1/13/2009 6:59:50 AM

Then Request.Form is not working, which is probably the case since the rendering on your page probably doesn't contain IDs of cName, cPhone, cBusiness, and cMessage.

So, try this: 

Dim strBody As String
strBody = (CType(MyFormView.FindControl("cName"), TextBox)).Text & vbCrLf
strBody = strBody & (CType(MyFormView.FindControl("cPhone"), TextBox)).Text & vbCrLf
strBody = strBody & (CType(MyFormView.FindControl("cBusiness"), TextBox)).Text & vbCrLf
strBody = strBody & (CType(MyFormView.FindControl("cMessage"), TextBox)).Text

mail.Body = strBody
 
Christopher Reed
"The oxen are slow, but the earth is patient."
0
Careed
1/13/2009 1:52:43 PM

Thanks!  My final product for other newbs.

FYI for newbs.

This is a solution for sending email from form where form is within InsertItemTemplate.

OnItemInserted Event of InsertButton...

Email is sent after data entered into the database. After email is sent, user is redirected to another .aspx page.

I home this is useful for others.

If somebody has thoughts to improve, please share

-------------------------------------------------------------

Sub Send2Mail(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)

'create the mail message

Dim mail As New MailMessage()

'Get From address and form contents

Dim cEmail As String

Dim strBody As String

cEmail = (CType(contactusFRM.FindControl("cEmailTextBox"), TextBox)).Text

'set the addresses

mail.From = New MailAddress(cEmail)

mail.To.Add(user@domain.com)

'set the content

mail.Subject = "Message from Contact Us Page"

strBody = "Name: " & (CType(contactusFRM.FindControl("cNameTextBox"), TextBox)).Text & vbCrLf

strBody = strBody & "Phone: " & (CType(contactusFRM.FindControl("cPhoneTextBox"), TextBox)).Text & vbCrLf

strBody = strBody & "Business Name: " & (CType(contactusFRM.FindControl("cBusinessTextBox"), TextBox)).Text & vbCrLfstrBody = strBody & "Mesage: " & (CType(contactusFRM.FindControl("cMessageTextBox"), TextBox)).Text

mail.Body = strBody

'send the message

Dim smtp As New SmtpClient("mail.domain.com")

smtp.Send(mail)

'redirect after data inserted to db

Response.Redirect("contactTest.aspx")

End Sub

End Class

 -------------------------------------------------------------

 TRU

0
TRU
1/14/2009 3:57:53 AM
Reply:

Similar Artilces:

Why do Sending SMTP Authenticated E-mail succeed using SmtpMail.Send() function but fail using SmtpClient.send() function ? Bugs in System.Net.Mail.SmtpClient when send a Authenticated E-mail?
I click btnOK button, the email can send OK, but click btnFail button,  the following error is displayed! why ? you can test the section code. The SMTP, username, password are valid!  Many thanks! "Syntax error, command unrecognized. The server response was: authentication failed,decode user password error" I have tested some other SMTP, somes is OK. I think there are some bugs with System.Net.Mail.SmtpClient when send a Authenticated E-mail with some SMTP!   //------------------------------------------.ASPX Code----------------------------------------...

Send email using System.Net.Mail
hi to all,  while i am sending mail to gmail ,i am facing problem.but i can send mail to other smtp adress like(smtp.horasoft.in)plz give advice how to send email to gmail(i didn't give any details other than  below code).thank you in advance.   protected void btnSubmit_Click(object sender, EventArgs e)        {                                     &nbs...

Sending email using System.net.Mail
 I am trying to send email using Asp .Net. I am using System.Net.Mail namespace. The code i written is below MailMessage message = new MailMessage(); message.From = new MailAddress("myemail@domain.com"); message.To.Add(new MailAddress("someone@domain.com")); message.Subject = "Test"; message.Body = "This is a test message"; message.IsBodyHtml = false; SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587); mailClient.Credentials = ne...

HOW TO: Send email using System.Net.Mail
 Looks like they locked the thread in the FAQ section, so I'll just ask my question here. I"m using a version of the System.Net.Mail class that was posted in the FAQ section. I'm trying to use it like this:            string from = EmailTextBox.Text;            string to = ContactIdentifier.EmailAddress;            string bcc = "";            strin...

HOW TO: Send email using System.Net.Mail
Below is a C# and VB.NET class that demonstrates using System.Net.Mail to send an email. Download C# System.Net.Mail HelperDownload VB.NET System.Net.Mail Helper Calling the function from code MailHelper.SendMailMessage("fromAddress@yourdomain.com", "toAddress@yourdomain.com", "bccAddress@yourdomain.com", "ccAddress@yourdomain.com", "Sample Subject", "Sample body of text for mail message") MailHelper.cs using System.Net.Mail; public class MailHelper{   /// <summary>   /// Sends an mail ...

Sending Mail Using System.Net.Mail with out using User credentials
HI, I have an application where in i send mails based on some condition, the user is already authenticated, so i need not check the User Credentials.Right now this is how the piece lokks:- mailClient.Credentials = new NetworkCredential(USERID, USER_PWD,DOMAIN); I want to send the mail, with out validating the user credentials, Can i skip the above line. Please post aqlong with the sample code.   Thanx in Advance. Anil Kumar.   I think you cannot skip. but store user credentials in session variables after login and then pass.If this post was useful to you, please mark it as...

Sending Email through System.Net.Mail is generating errors "Failure Sending mail
hi Sending Email through System.Web.Mail is working fine but System.Net.Mail is generating errors "Failure Sending mail  i treid in all possible ways but did't  pls help in giving a solution thanks & Regards vittal Maybe you can show us some code and post the exact error mesg as well (by looking at the value in ex.tostring)?My HomePage - www.findingsteve.net"It is more blessed to give than to receive." Acts 20: 35 (NIV, Bible)Progress - "Never discourage anyone...who continually makes progress, no matter how slow." Plato System.Web.Ma...

get mail using System.Net.Mail
How can i get Email usign System.Net.Mail ?? Hello poloxy  ,the System.Net.Mail used only for sending emails and not to receive them.Read the full documentation at  MSDN Library http://technet.microsoft.com/en-us/library/system.net.mail.aspx  Hosam Kamel Remember to click on Mark as answer on the post that helped you SO how can I receive mail ? Try one of these pop3 librarieshttp://www.codeproject.com/info/search.aspx?artkw=pop3  Hosam Kamel Remember to click on Mark as answer on the post that helped you HI,   if you want to send email by using System....

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Is it possible to specify which font to use when sending email with Imports System.Net.Mail?
I've got a basic vb.net page that after the user clicks submit, I send a confirmation email with System.Net.Mail.   I'm able to bold, italics and add horizontal rules, but would also like to set the font it is sent in as Verdana.    I searched here for how to change the font  http://msdn.microsoft.com/en-us/library/system.net.mail.aspx   but didn't have any luck.  Do you have any suggestions?  Never make important decisions on a Monday! Yeah if it's a HTML email then use <span style="font: 12px arial;">Text i...

cannot send email from webpage using System.Net.Mail on external smtp server
Every time I am trying to send email from my webpage, or using passwordrecovery tool , i get following error :: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed I went through all the existing posts, but none of them worked for me. I have already checked http://www,systemwebmail.com/ web.config settings are as follows <system.net>    <mailSettings>      <smtp from="noreply@allure.com"&g...

Problem in sending mail using system.net.mail
I am using C# and ASP.Net2.0 for sending mail. But my problem is it is not being sent. I am not being able to understand it. I am using my gmail account for it. I am using System.Net and System .Net.Mail for sending the same. But i am getting the error ''Failure Sending Mail. Cannot connect to the server" . I have internet connection. Plz help me. It's urgent. I am attaching my code.  MailMessage mailMsg = new MailMessage();MailAddress ma = new MailAddress(username@gmail.com); mailMsg.From = ma; mailMsg.To.Add(s);mailMsg.Subject = "Your...

.net 2 beta 2 - System.Net.Mail
Hi guysI'm using the System.Net.Mail namespace in .net version 2, beta 2, to send out some HTML formatted e-mails.However, for some reason when the e-mail are sent out some of the full stops from the e-mail are removed.For example, part of the e-mail contains this code<img src="http://www.avonandsomerset.police.uk/images/grey_box_bottom.gif" alt="">But this is what the code is like when the e-mail source code is viewed<img src="http://www.avonandsomerset.police.uk/images/grey_box_bottomgif" alt="">Is this a known bug in beta 2? If so, where can I view a list of known bugs an...

need help: sending mail using system.net.mail
hi thr.. i am some help urgently.. i need to send mail using asp.net the cs code is          System.Net.Mail.MailMessage MyMail = new System.Net.Mail.MailMessage();        SmtpClient SmtpMail = new SmtpClient();            try            {                MyMail.From = new MailAddress("balu.naren@gmail.com");  &n...

Web resources about - Send Email from form using system.net.mail - asp.net.getting-started

List of areas in the United States National Park System - Wikipedia, the free encyclopedia
The National Park System of the United States is the collection of physical properties owned or administered by the National Park Service . This ...

Secrets of North Korea's Red Star computer operating system revealed
... researchers have delved into the secretive state's computer code and found a dichotomy. Seoul: North Korea's homegrown computer operating system ...

Andrew Hastie: Ice freezes addicts in justice system
AS a newly elected Member of the Federal Parliament, I have been challenged by numerous experiences over the past three months.

First-class refugees: Malaysia's two-tier system
Malaysian government extends helping hand to Syrian refugees, as thousands of other refugees struggle in illegal limbo.

Company Shares of Cisco Systems, Inc. (NASDAQ:CSCO) Rally 4.23%
News Watch International Company Shares of Cisco Systems, Inc. (NASDAQ:CSCO) Rally 4.23% American Trade Journal Shares of Cisco Systems, Inc. ...

Lawsuits aim to upend bail bond system throughout the U.S.
Opponents argue bail system unconstitutionally treats poor and wealthy suspects differently

Thousands Of Flights Canceled, Delayed As Storm System Wreaks Holiday Travel Havoc
Even if you haven’t had to fly anywhere yesterday or today, you’re likely aware that there’s a large storm system currently duffing up air travel ...

Short Interest in Cisco Systems, Inc. (CSCO) Declines By 9.9%
American Trade Journal Short Interest in Cisco Systems, Inc. (CSCO) Declines By 9.9% Dakota Financial News Cisco Systems logo Cisco Systems, ...

Value of remote power systems expected to total nearly US$200 billion from 2015-2024, says Navigant
... and nanogrids in an off-grid environment mirrors the dynamics in a grid-tied environment in developed industrial economies, where the systems ...

Ben Heck's Holiday Present Protection System
... present thieves when Ben, Felix and Karen hack apart a set of weighing scales with a PIC microcontroller and key lock to use as an alarm system, ...

Resources last updated: 12/29/2015 2:20:15 AM