Where it says "*Network host here*", that is where I need to put the local host in. Although, I don't know where to find my host or where to set it up. I was watching Chris Pels tutorial on ASP.net and he added the local host as smtp.east.cox.net.
I know this isn't related to this topic, but visual web developer is what i'm using.
What does this show me? What part do I need to look at?
Ur codes, plz:
<div sizset="8" sizcache="2">
Below is a C# and VB.NET class that demonstrates using System.Net.Mail to send an email.
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;
publicclassMailHelper { ///<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 staticvoidSendMailMessage(stringfrom,stringto,stringbcc,stringcc,stringsubject,stringbody) { // Instantiate a new instance of MailMessage MailMessagemMailMessage =newMailMessage();
// Set the sender address of the mail message mMailMessage.From =newMailAddress(from); // Set the recepient address of the mail message mMailMessage.To.Add(newMailAddress(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(newMailAddress(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(newMailAddress(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 SmtpClientmSmtpClient =newSmtpClient(); // Send the mail message mSmtpClient.Send(mMailMessage); } }
MailHelper.vb
Imports
System.Net.Mail
Public
ClassMailHelper '''
<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 SharedSub
SendMailMessage(ByVal
fromAs
String,
ByValrecepient
AsString,ByVal
bccAs
String,
ByValcc
AsString,
ByValsubject
AsString,ByVal
bodyAs
String) ' Instantiate a new instance of MailMessage DimmMailMessage
AsNewMailMessage()
' Set the sender address of the mail message mMailMessage.From =NewMailAddress(from) ' Set the recepient address of the mail message mMailMessage.To.Add(NewMailAddress(recepient))
' Check if the bcc value is nothing or an empty string IfNot
bccIs
NothingAnd
bcc <>String.EmptyThen ' Set the Bcc address of the mail message mMailMessage.Bcc.Add(NewMailAddress(bcc)) EndIf
' Check if the cc value is nothing or an empty value IfNot
ccIs
NothingAnd
cc <>String.EmptyThen ' Set the CC address of the mail message mMailMessage.CC.Add(NewMailAddress(cc)) EndIf
' 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 DimmSmtpClient
AsNewSmtpClient() ' Send the mail message mSmtpClient.Send(mMailMessage) EndSub EndClass
Partial Public Class _Default
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 EventArgs) Handles btnSend.Click
Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
mailMessage.From = New System.Net.Mail.MailAddress(txtFromAddress.Text.Trim())
mailMessage.To.Add(New System.Net.Mail.MailAddress(txtToAddress.Text.Trim())
mailMessage.Subject = txtSubject.Text.Trim()
mailMessage.Body = txtBody.Text.Trim()
Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
smtpClient.Send(mailMessage)
End Sub
End Class
ThunderWaffe...
Member
17 Points
62 Posts
Emails with forms - Help needed
Aug 12, 2012 06:59 AM|LINK
I'm setting up an email form on my site and I need to find my Network host. Where can I find my network host? This is what i'm using it in:
<system.net> <mailSettings> <smtp> <network host="smtp.*NETWORK HOST HERE*"/> </smtp> </mailSettings> </system.net>Where it says "*Network host here*", that is where I need to put the local host in. Although, I don't know where to find my host or where to set it up. I was watching Chris Pels tutorial on ASP.net and he added the local host as smtp.east.cox.net.
I know this isn't related to this topic, but visual web developer is what i'm using.
Thanks,
TimoYang
Contributor
3732 Points
1275 Posts
Re: Emails with forms - Help needed
Aug 12, 2012 08:15 AM|LINK
Just ask ur Email providor to find that……Here're some samples:
1)Google:smtp.gmail.com
2)Hotmail:Update ur Email for payment u can use that!
3)Yahoo:smtp.yahoo.com
ThunderWaffe...
Member
17 Points
62 Posts
Re: Emails with forms - Help needed
Aug 12, 2012 08:51 AM|LINK
<system.net> <mailSettings> <smtp> <network host="smtp.gmail.com"/> </smtp> </mailSettings> </system.net>Would I do it like this if I had a gmail account?
TimoYang
Contributor
3732 Points
1275 Posts
Re: Emails with forms - Help needed
Aug 12, 2012 09:09 AM|LINK
Now plz see this:
http://forums.asp.net/t/971802.aspx
ThunderWaffe...
Member
17 Points
62 Posts
Re: Emails with forms - Help needed
Aug 12, 2012 09:16 AM|LINK
What does this show me? What part do I need to look at?
TimoYang
Contributor
3732 Points
1275 Posts
Re: Emails with forms - Help needed
Aug 12, 2012 09:44 AM|LINK
Ur codes, plz:
<div sizset="8" sizcache="2">Below is a C# and VB.NET class that demonstrates using System.Net.Mail to send an email.
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 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);
}
}
MailHelper.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
Web.config
<?
xml version="1.0"?>
</div><configuration>
<system.net>
<mailSettings>
<smtp from="defaultEmail@yourdomain.com">
<network host="smtp.yourdomain.com" port="25" userName="yourUserName" password="yourPassword"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
ThunderWaffe...
Member
17 Points
62 Posts
Re: Emails with forms - Help needed
Aug 12, 2012 10:32 AM|LINK
Partial Public Class _Default 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 EventArgs) Handles btnSend.Click Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage() mailMessage.From = New System.Net.Mail.MailAddress(txtFromAddress.Text.Trim()) mailMessage.To.Add(New System.Net.Mail.MailAddress(txtToAddress.Text.Trim()) mailMessage.Subject = txtSubject.Text.Trim() mailMessage.Body = txtBody.Text.Trim() Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient() smtpClient.Send(mailMessage) End Sub End ClassSo wait, you need my code?
ThunderWaffe...
Member
17 Points
62 Posts
Re: Emails with forms - Help needed
Aug 12, 2012 10:33 AM|LINK
<?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" /> <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> </sectionGroup> </sectionGroup> </sectionGroup> </configSections> <system.net> <mailSettings> <smtp> <network host="smtp.gmail.com"/> </smtp> </mailSettings> </system.net> <appSettings/> <connectionStrings/> <system.web> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development. Visual Basic options: Set strict="true" to disallow all data type conversions where data loss can occur. Set explicit="true" to force declaration of all variables. --> <compilation debug="false" strict="false" explicit="true"> <assemblies> <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> </assemblies> </compilation> <pages> <namespaces> <clear /> <add namespace="System" /> <add namespace="System.Collections" /> <add namespace="System.Collections.Generic" /> <add namespace="System.Collections.Specialized" /> <add namespace="System.Configuration" /> <add namespace="System.Text" /> <add namespace="System.Text.RegularExpressions" /> <add namespace="System.Linq" /> <add namespace="System.Xml.Linq" /> <add namespace="System.Web" /> <add namespace="System.Web.Caching" /> <add namespace="System.Web.SessionState" /> <add namespace="System.Web.Security" /> <add namespace="System.Web.Profile" /> <add namespace="System.Web.UI" /> <add namespace="System.Web.UI.WebControls" /> <add namespace="System.Web.UI.WebControls.WebParts" /> <add namespace="System.Web.UI.HtmlControls" /> </namespaces> <controls> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </controls> </pages> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. --> <authentication mode="Windows" /> <!-- The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace. <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> --> <httpHandlers> <remove verb="*" path="*.asmx"/> <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/> </httpHandlers> <httpModules> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </httpModules> </system.web> <system.codedom> <compilers> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5"/> <providerOption name="OptionInfer" value="true"/> <providerOption name="WarnAsError" value="false"/> </compiler> </compilers> </system.codedom> <!-- The system.webServer section is required for running ASP.NET AJAX under Internet Information Services 7.0. It is not necessary for previous version of IIS. --> <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules> <remove name="ScriptModule" /> <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </modules> <handlers> <remove name="WebServiceHandlerFactory-Integrated"/> <remove name="ScriptHandlerFactory" /> <remove name="ScriptHandlerFactoryAppServices" /> <remove name="ScriptResource" /> <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </handlers> </system.webServer> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>TimoYang
Contributor
3732 Points
1275 Posts
Re: Emails with forms - Help needed
Aug 13, 2012 01:26 AM|LINK
No i don't need ur codes at all——I only offer ur a solution.
ThunderWaffe...
Member
17 Points
62 Posts
Re: Emails with forms - Help needed
Aug 13, 2012 07:54 AM|LINK
Okay but what part of that did I need to look at? It didn't have anything to do with local network host?