Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Sending email

Author  Topic 

valedaw2
Yak Posting Veteran

50 Posts

Posted - 2009-12-02 : 12:44:56
I have a form written in HTML, saved in an aspx file. I need to send an email with form content and attachments. I am in an asp.net environment. This is all new to me. Will it be necessary to convert the code to send an email? If so, will be a problem with the way it is coded?


Here is the code:

<code>
<form action="sendEmail()" method="post" enctype="multipart/form-data" id="infoForm" name="infoForm" onsubmit="return validateForm();" >
<label class="requiredField">
<input type="hidden" class="DEPENDS ON os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt OR custO BEING lender OR custO BEING borrower OR custO BEING othr"/>
<span class="requiredField"><strong><em>*Required fields</em></strong></span></label>
<label id=genllbl> <input type="hidden" id="error_msg" name= "error_msg" /><strong>General Information</strong>
<input type="radio" name="os" id="genlOpt" value="genlOpt" onclick = "checkValue(infoForm)"/>
</label>
<label id=custlbl><strong>     Customer Care</strong>
<input type="radio" name="os" id="custOpt" value="custOpt" onclick = "checkValue(infoForm)"/>
</label>
<label id=medialbl><strong>     Media Kit</strong>
<input type="radio" name="os" id="mediaOpt" value="mediaOpt" onclick = "checkValue(infoForm)"/>
</label>
<strong>
<label id=careerlbl>     Career Opportunities
<input type="radio" name="os" id="careerOpt" value="careerOpt" onclick = "checkValue(infoForm)"/>
</label> <br />
<label><strong>Are you a: Member Lender</strong><a href="#" class="hintanchor" onmouseover="showhint('A member of an organization that subscribes to and utilizes PayNet’s services.', this, event, '150px')">(?)</a>
<input id="lender" type="radio" name="custO" class="DEPENDS ON os BEING custOpt" value="lender" onclick="setSubj()"/>
</label>
<label><strong>   Borrower</strong><a href="#" class="hintanchor" onmouseover="showhint('An organization or sole proprietor seeking financing from one of PayNet’s Member Lenders.', this, event, '150px')">(?)</a>
<input id="borrower" type="radio" name="custO" value="borrower" class="DEPENDS ON os BEING custOpt" onclick="setSubj()"/></label>
<label><strong>   Other</strong><a href="#" class="hintanchor" onmouseover="showhint('An organization or sole proprietor that does not fit the profile of a Member Lender or a Borrower.', this, event, '150px')" >(?)</a><input id="othr" type="radio" name="custO" value="othr" class="DEPENDS ON os BEING custOpt" onclick="setSubj()"/></label>

<p>
<label><strong>Do you want a free copy of your PayNet Credit History Report? Yes</strong>
<input type="radio" name="chrRqst" class="DEPENDS ON custO BEING borrower" value="yes"/>
</label>
<label><strong>   No</strong>
<input type="radio" name="chrRqst" value="no" class="DEPENDS ON custO BEING borrower"/></label>
</p>
<p>
<label><strong>How would you like to receive the report? By Email</strong>
<input type="radio" name="chrRec" class="DEPENDS ON chrRqst BEING yes" value="email"/>
</label>
<label><strong>   By Fax</strong>
<input type="radio" name="chrRec" value="fax" class="DEPENDS ON chrRqst BEING yes" />
</label>
</p>
<p>
<label><input type='hidden' class="DEPENDS ON chrRec BEING email"/>
<em><strong>Please complete the form below <br />
OR <br />
If you would like to submit your request by email</strong>, please submit your request to: <a href="mailto:support@paynetonline.com">support@paynetonline.com</a><br />
Your company's email address must include the company's/organizations name as part of the domain name, such as mike@abccompany.com.
<br />
Please enter in the subject line of the email - "Request for Credit History Report";<br />
Please include in the body of your email: <br />
The company's/organization's full address including city and state;<br />
A contact person and phone number in case we have additional questions
</em></label>
</p>
<p>
<label><input type='hidden' class="DEPENDS ON chrRec BEING fax"/>
<em><strong>Please complete the form below <br />
OR <br />
If you would like to submit your request by fax</strong>, please submit your request on company letterhead and send your fax to: 847-965-9828, Attention:Support.<br />
Please include in the body of your fax:<br />
"Request for Credit History Report";<br />
The company's/organization's full address including city and state;<br />
A contact person and phone number in case we have additional questions;<br />
The fax number where you would like your Report sent
</em></label>
</p>
<p>
<label><strong>Would you like to download the Media Kit (PDF)?</strong>
<input name="medOpt" type="radio" class="DEPENDS ON os BEING mediaOpt" onclick="doredirect();" value="dwnld"/>
</label></p>
<p>
<label><strong>Or request a hard copy to be mailed to you?</strong>
<input name="medOpt" type="radio" class="DEPENDS ON os BEING mediaOpt" value="hrdCpy" onclick="setSubj()"/>
</label>
</p>
<label>
<input type="hidden" class="DEPENDS ON os BEING careerOpt"/>
<font color="#000099">
<strong><em>Contact Information:<br />
=================================================================<br />
</em></strong></font></label>
<p>
<label><strong>  Company Name</strong>
<input name="cmpyName" type="text" class="DEPENDS ON os BEING genlOpt OR medOpt BEING hrdCpy OR custO BEING lender OR custO BEING borrower OR custO BEING othr" id="cmpyName" size="60" maxlength="60"/>
<br />
<br />
</label>
<label>

<span class="requiredField"><strong>*</strong></span><strong>First Name</strong>
<input name="firstName" type="text" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" id="firstName" value="" size="30" maxlength="30"/>
</label>
<label><span class="requiredField"><strong>*</strong></span><strong>Last Name</strong>
<input name="lastName" type="text" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" id="lastName" value="" size="30" maxlength="50"/>
</label>
<br />
</p>
<p>
<label><span class="requiredField"><strong>*</strong></span><strong>Address1 </strong>
<input name="add1" type="text" class="DEPENDS ON custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" id="add1" value="" size="50" maxlength="50"/>
</label>
</p>
<p>
<label><strong>  Address2
</strong>
<input name="add2" type="text" class="DEPENDS ON custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" id="add2" value="" size="50" maxlength="50"/>
</label>
</p>
<p>
<label><span class="requiredField"><strong>*</strong></span><strong>Country:</strong> United States
<input type="radio" name="cntryO" value="US" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt"/>
</label>
<label>Canada<input type="radio" name="cntryO" value="CA" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt"/></label>
<br />
</p>
<p>
<label><span class="requiredField"><strong>*</strong></span><strong>City</strong>
<input name="addCity" type="text" class="DEPENDS ON os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt OR custO BEING othr" id="addCity" onfocus="valCountry(infoForm)" size="25" maxlength="25"/>
</label>
<label><span class="requiredField"><strong>*</strong></span><strong>Province</strong>
<select name="Province" id="Province" class="DEPENDS ON cntryO BEING CA AND os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt AND CONFLICTS WITH custO BEING lender">
<option value="">SELECT ONE</option>
<option value="AB">Alberta</option>
<option value="BC">British Columbia</option>
<option value="MB">Manitoba</option>
<option value="NB">New Brunswick</option>
<option value="NL">Newfoundland and Labrador</option>
<option value="NS">Nova Scotia</option>
<option value="NT">Northwest Territories</option>
<option value="NU">Nunavut</option>
<option value="ON">Ontario</option>
<option value="PE">Prince Edward Island</option>
<option value="QC">Quebec</option>
<option value="SK">Saskatchewan</option>
<option value="YT">Yukon</option>
</select>
</label>
<label><span class="requiredField"><strong>*</strong></span><strong>State</strong>
<select name="addState" id="addState" class="DEPENDS ON cntryO BEING US AND os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt AND CONFLICTS WITH custO BEING lender">
<option value="">SELECT ONE</option>
<option value='0' >Alabama</option>
<option value='1' >Alaska</option>
<option value='2' >Arizona</option>
<option value='3' >Arkansas</option>
<option value='4' >California</option>
<option value='5' >Colorado</option>
<option value='6' >Connecticut</option>
<option value='7' >Delaware</option>
<option value='8' >District of Columbia</option>
<option value='9' >Florida</option>
<option value='10' >Georgia</option>
<option value='11' >Hawaii</option>
<option value='12' >Idaho</option>
<option value='13' >Illinois</option>
<option value='14' >Indiana</option>
<option value='15' >Iowa</option>
<option value='16' >Kansas</option>
<option value='17' >Kentucky</option>
<option value='18' >Louisiana</option>
<option value='19' >Maine</option>
<option value='20' >Maryland</option>
<option value='21' >Massachusetts</option>
<option value='22' >Michigan</option>
<option value='23' >Minnesota</option>
<option value='24' >Mississippi</option>
<option value='25' >Missouri</option>
<option value='26' >Montana</option>
<option value='27' >Nebraska</option>
<option value='28' >Nevada</option>
<option value='29' >New Hampshire</option>
<option value='30' >New Jersey</option>
<option value='31' >New Mexico</option>
<option value='32' >New York</option>
<option value='33' >North Carolina</option>
<option value='34' >North Dakota</option>
<option value='35' >Ohio</option>
<option value='36' >Oklahoma</option>
<option value='37' >Oregon</option>
<option value='38' >Pennsylvania</option>
<option value='39' >Puerto Rico</option>
<option value='40' >Rhode Island</option>
<option value='41' >South Carolina</option>
<option value='42' >South Dakota</option>
<option value='43' >Tennessee</option>
<option value='44' >Texas</option>
<option value='45' >Utah</option>
<option value='46' >Vermont</option>
<option value='47' >Virginia</option>
<option value='48' >Washington</option>
<option value='49' >West Virginia</option>
<option value='50' >Wisconsin</option>
<option value='51' >Wyoming</option>
</select>
</label>
</p>
<p>
<label>
<span class="requiredField"><strong>*</strong></span><strong>Zip/Postal Code</strong>
<input name="addZip" type="text" class="DEPENDS ON custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" id="addZip" size="9" maxlength="9"/></label>
</p>
<p>
<label>
<strong>  Bus Phone</strong>
<input name="busPhone" type="text" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" id="busPhone" size="10" maxlength="10"/>
</label>
<label><strong>Cell Phone</strong>
<input name="cellPhone" type="text" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" id="cellPhone" size="10" maxlength="10"/>
</label>
<label><strong>Home Phone</strong>
<input name="hmPhone" type="text" class="DEPENDS ON os BEING careerOpt" id="hmPhone" size="10" maxlength="10"/>
</label>
<br />
</p>
<p>
<label><strong>  Fax</strong>
<input name="addFax" type="text" class="DEPENDS ON custO BEING lender OR chrRec BEING fax OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" id="addFax" size="12" maxlength="12"/>
</label>
<br />
</p>
<p>
<label><strong>  Email</strong>
<input name="emailAdr" type="text" class="DEPENDS ON os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt OR custO BEING lender OR custO BEING othr OR chrRec BEING email" id="emailAdr" size="60" maxlength="60"/>
</label>
</p>
<label><span class="requiredField"><strong>*</strong></span><strong>Preferred method of contact</strong>
<select name="prefCnt" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" id="prefCnt" onfocus="valCntInfo()" >
<option value="">SELECT ONE</option>
<option value="bus">Business Phone</option>
<option value="cell">Cell/Mobile Phone</option>
<option value="home">Home Phone</option>
<option value="fax">Fax</option>
<option value="email">Email </option>
</select>
</label>
<label><strong>Best time to contact you
</strong>
<input type="text" name="conTime" id="conTime" class="DEPENDS ON os BEING careerOpt"/>
</label><br /><br />
<label>
<input type="hidden" class="DEPENDS ON os BEING careerOpt"/>
<font color="#000099">
<strong><em>Application Information:<br />
=================================================================</em></strong></font></label>
<label><strong><br />
<br />
  Upload your Cover Letter</strong>
<input type="file" name="upCover" id="upCover" class="DEPENDS ON os BEING careerOpt"/>
</label>
<label><strong><br />
<em>  OR</em></strong><br />
<strong>  Copy and paste your Cover Letter</strong><br />
<textarea name="pstCvr" cols="50" rows="14" class="DEPENDS ON os BEING careerOpt" id="pstCvr"></textarea>
</label>
<p> <label><strong>  Upload your Resume</strong>
<input type="file" name="upResume" id="upResume" class="DEPENDS ON os BEING careerOpt"/>
<br />
</label>
<label><strong><em>  OR</em></strong><br />
<strong>  Copy and paste your Resume</strong><br />
<textarea name="pstResume" cols="50" rows="14" class="DEPENDS ON os BEING careerOpt" id="pstResume"></textarea>
</label>
</p>
<div>
<label>
<select name="firstlevel" id="firstlevel" disabled="disabled" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" >
</select>
<strong><span class="requiredField">*</span></strong><strong>Subject Line</strong></label>
<select name="secondlevel" id="secondlevel" value="" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" onblur="check2nd();">
</select>
</div>

<label id=displayOthr style="visibility:hidden" ><strong><br />
<span class="requiredField">*</span><strong>Other Request Subject</strong>
<input name="subjOthr" type="text" id="subjOthr" size="60" maxlength="60" />
</label>
<label>
<strong><br />
<br />
  What can we do for you? </strong>(max. 300 characters)<br />
<textarea name="comments" cols="60" rows="5" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy" id="comments" style="width:250px" onfocus="valCntInfo()"></textarea>
</label>
<label class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy">
<div id="comments-status" > </div>
</label>
<br />
<label><input type="reset" name="reset" id="reset" value="Reset" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt"/>
</label>
<label><input type="submit" name="Submit" id="Submit" value="Submit" class="DEPENDS ON custO BEING lender OR custO BEING borrower OR custO BEING othr OR os BEING genlOpt OR medOpt BEING hrdCpy OR os BEING careerOpt" />
</label>
</form>
</code>

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2009-12-02 : 16:49:30
html and .net are two totally different animals and work in different ways.

see this, as it might help
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2009-12-02 : 16:50:03
opps sorry

http://www.dotnettutorials.com/tutorials/email/
Go to Top of Page

valedaw2
Yak Posting Veteran

50 Posts

Posted - 2009-12-03 : 08:58:51
It looks like I will have to convert the form in order to send an email. Looking at the code, is it just a matter of adding the aspx: information in the <label> tag?
Go to Top of Page

valedaw2
Yak Posting Veteran

50 Posts

Posted - 2009-12-03 : 08:59:42
By the way, thanks so much for responding.
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2009-12-03 : 12:00:08
dont understand what you mean.
Go to Top of Page

sathiesh2005
Yak Posting Veteran

85 Posts

Posted - 2009-12-04 : 04:09:46
Hi
I dont understand your code. But sending email is very simple.

plese refer this link.
http://www.dotnettutorials.com/tutorials/email/email-auth-aspnet2-csharp.aspx


Regards,
Sathieshkumar. R
Go to Top of Page

Paul daniel
Starting Member

3 Posts

Posted - 2009-12-28 : 04:34:09
Hi

Try this it'll be helpful to u

code in c#

using System.Net.Mail;

public class MailHelper
{
/// <summary>
/// Sends an mail message
/// </summary>
/// <param name="from">Sender address</param>
/// <param name="to">Recepient address</param>
/// <param name="bcc">Bcc recepient</param>
/// <param name="cc">Cc recepient</param>
/// <param name="subject">Subject of mail message</param>
/// <param name="body">Body of mail message</param>
public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
{
// Instantiate a new instance of MailMessage
MailMessage mMailMessage = new MailMessage();
// Set the sender address of the mail message
mMailMessage.From = new MailAddress(from);
// Set the recepient address of the mail message
mMailMessage.To.Add(new MailAddress(to));

// Check if the bcc value is null or an empty string
if ((bcc != null) && (bcc != string.Empty))
{
// Set the Bcc address of the mail message
mMailMessage.Bcc.Add(new MailAddress(bcc));
}
// Check if the cc value is null or an empty value
if ((cc != null) && (cc != string.Empty))
{
// Set the CC address of the mail message
mMailMessage.CC.Add(new MailAddress(cc));
} // Set the subject of the mail message
mMailMessage.Subject = subject;
// Set the body of the mail message
mMailMessage.Body = body;

// Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = true;
// Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal;

// Instantiate a new instance of SmtpClient
SmtpClient mSmtpClient = new SmtpClient();
// Send the mail message
mSmtpClient.Send(mMailMessage);
}
}

Code in vb

Imports System.Net.Mail

Public Class MailHelper
''' <summary>
''' Sends an mail message
''' </summary>
''' <param name="from">Sender address</param>
''' <param name="recepient">Recepient address</param>
''' <param name="bcc">Bcc recepient</param>
''' <param name="cc">Cc recepient</param>
''' <param name="subject">Subject of mail message</param>
''' <param name="body">Body of mail message</param>
Public Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, ByVal subject As String, ByVal body As String)
' Instantiate a new instance of MailMessage
Dim mMailMessage As New MailMessage()

' Set the sender address of the mail message
mMailMessage.From = New MailAddress(from)
' Set the recepient address of the mail message
mMailMessage.To.Add(New MailAddress(recepient))

' Check if the bcc value is nothing or an empty string
If Not bcc Is Nothing And bcc <> String.Empty Then
' Set the Bcc address of the mail message
mMailMessage.Bcc.Add(New MailAddress(bcc))
End If

' Check if the cc value is nothing or an empty value
If Not cc Is Nothing And cc <> String.Empty Then
' Set the CC address of the mail message
mMailMessage.CC.Add(New MailAddress(cc))
End If

' Set the subject of the mail message
mMailMessage.Subject = subject
' Set the body of the mail message
mMailMessage.Body = body

' Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = True
' Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal

' Instantiate a new instance of SmtpClient
Dim mSmtpClient As New SmtpClient()
' Send the mail message
mSmtpClient.Send(mMailMessage)
End Sub
End Class

Go to Top of Page
   

- Advertisement -