introlux
asked on
Sending an e-mail via set template
I am using MS Visual Studio 2005 .Net C#. I am trying to create a sample e-mail setup. i.e.
I would like an e-mail set up when a user clicks on the button will create an email notification sending out to an e-mail address saying data submitted etc... but also displaying what in the email whatever data has been inserted in that particular txt box.
Thanks!
introlux
I would like an e-mail set up when a user clicks on the button will create an email notification sending out to an e-mail address saying data submitted etc... but also displaying what in the email whatever data has been inserted in that particular txt box.
Thanks!
introlux
ASKER
I would only like the data from one txt box rather than all the values enetered by the user.
introlux
introlux
then simply this
Andrew
Andrew
protected void TemplatedEmailFormData(object sender, EventArgs e)
{
MailAddress FromAddress = new MailAddress("user1@email.com");
MailAddress ToAddress = new MailAddress("user1@email.com");
MailMessage message = new MailMessage(FromAddress, ToAddress);
message.Body = YourTextBox.Text;
SmtpClient client = new SmtpClient("127.0.0.1", 25);
client.Send(message);
}
ASKER
What about the subject of the e-mail?? where does that go??
Thanks,
introlux
Thanks,
introlux
Cheers,
Andrew
Andrew
protected void TemplatedEmailFormData(object sender, EventArgs e)
{
MailAddress FromAddress = new MailAddress("user1@email.com");
MailAddress ToAddress = new MailAddress("user1@email.com");
MailMessage message = new MailMessage(FromAddress, ToAddress);
message.Body = YourTextBox.Text;
message.Subject = "Subject";
SmtpClient client = new SmtpClient("127.0.0.1", 25);
client.Send(message);
}
ASKER
I am sorry as I am on the beginner level. The code i assume is added into the CS file which I have. How will I ensure that this has run after the button has been clicked.
Also in the body, I would like to inserted the text.box while in a sentence. E.g. The new project txtPName.text has been commissioned.
How will I do this??
Also in the body, I would like to inserted the text.box while in a sentence. E.g. The new project txtPName.text has been commissioned.
How will I do this??
protected void TemplatedEmailFormData(object sender, EventArgs e)
{
MailAddress FromAddress = new MailAddress("project@theidfactor.com");
MailAddress ToAddress = new MailAddress("project@theidfactor.com");
MailMessage message = new MailMessage(FromAddress, ToAddress);
message.Subject = "New Project Has been commissioned";
message.Body = txtPName.Text 'Has now been commissioned';
SmtpClient client = new SmtpClient("127.0.0.1", 25);
client.Send(message);
}
ASKER
??????
OK, you are simply missing a plus sign:
Cheers
Andrew :-)
Cheers
Andrew :-)
protected void TemplatedEmailFormData(object sender, EventArgs e)
{
MailAddress FromAddress = new MailAddress("project@theidfactor.com");
MailAddress ToAddress = new MailAddress("project@theidfactor.com");
MailMessage message = new MailMessage(FromAddress, ToAddress);
message.Subject = "New Project Has been commissioned";
message.Body = txtPName.Text + 'Has now been commissioned';
SmtpClient client = new SmtpClient("127.0.0.1", 25);
client.Send(message);
}
oh and use double quotes not single quotes.
ASKER
I take it you put this code in the CS. But how will i execute this command???
thanks,
introlux
thanks,
introlux
you will have a Button, so you simple add this to its onclick event
OnClick="TemplatedEmailFor mData"
OnClick="TemplatedEmailFor
ASKER
What if I have a command already on the OnClick=
Is it possible to add two multiple commands???
Is it possible to add two multiple commands???
ASKER
????????
yes, so just add this code block, either at the end or the beginning of your current function
aslong as you code between the two curly brackets you can put as much code in there as you want.
Andrew
aslong as you code between the two curly brackets you can put as much code in there as you want.
Andrew
MailAddress FromAddress = new MailAddress("project@theidfactor.com");
MailAddress ToAddress = new MailAddress("project@theidfactor.com");
MailMessage message = new MailMessage(FromAddress, ToAddress);
message.Subject = "New Project Has been commissioned";
message.Body = txtPName.Text + 'Has now been commissioned';
SmtpClient client = new SmtpClient("127.0.0.1", 25);
client.Send(message);
ASKER
When trying to run it, I am getting the following error message:
Compiler Error Message: CS0246: The type or namespace name 'MailAddress' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 21: protected void TemplatedEmailFormData(obj ect sender, EventArgs e)
Line 22: {
Line 23: MailAddress FromAddress = new MailAddress("project@theid factor.com ");
Line 24: MailAddress ToAddress = new MailAddress("project@theid factor.com ");
Line 25: MailMessage message = new MailMessage(FromAddress, ToAddress);
Compiler Error Message: CS0246: The type or namespace name 'MailAddress' could not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 21: protected void TemplatedEmailFormData(obj
Line 22: {
Line 23: MailAddress FromAddress = new MailAddress("project@theid
Line 24: MailAddress ToAddress = new MailAddress("project@theid
Line 25: MailMessage message = new MailMessage(FromAddress, ToAddress);
at the top you need to inlude this line
using System.Net.Mail;
using System.Net.Mail;
ASKER
I get this error now:
Compiler Error Message: CS0149: Method name expected
Source Error:
Line 563:</asp:Table>
Line 564: <br />
Line 565:<asp:Button id="btnLogin" runat="server" Text="Print" onClick="AddCredentials_Cl ick, TemplatedEmailFormData" Height="55px" Width="84px" />
Line 566:</form>
Line 567:</td>
Compiler Error Message: CS0149: Method name expected
Source Error:
Line 563:</asp:Table>
Line 564: <br />
Line 565:<asp:Button id="btnLogin" runat="server" Text="Print" onClick="AddCredentials_Cl
Line 566:</form>
Line 567:</td>
ASKER
??????????????
ASKER
This is a very simple error which I have looked all over the internet but no luck. I have tried every possible ways to have multiple commands being executed
Thanks
Thanks
Before you attempt this you need to read up on Basic C# syntax and event handlers, as I am struggling to jump in and fill all the gaps. Have a read through some tutorials first.
ASKER
I have read through some examples and all only explain how to execute one command. Hence I have two:
AddCredentials_Click
TemplatedEmailFormData
AddCredentials_Click = This adds data into the access database
TemplatedEmailFormData = This sends an e-mail
I want both of these to run at the same time the button 'Print' is clicked by the user.
Thanks
AddCredentials_Click
TemplatedEmailFormData
AddCredentials_Click = This adds data into the access database
TemplatedEmailFormData = This sends an e-mail
I want both of these to run at the same time the button 'Print' is clicked by the user.
Thanks
check this.
I have
pubilc void DoSomethingA()
{
}
and
pubilc void DoSomethingB()
{
}
I could simply write this:
pubilc void DoSomethingA(object sender,EventArgs e)
{
DoSomethingB();
DoSomethingC();
}
OnClick="DoSomethingA"
So here I call DoSomethingA on the onclick and in turn it then calls the other two functions DoSomthingB and DoSomethingC
Cheers
Andrew :-)
I have
pubilc void DoSomethingA()
{
}
and
pubilc void DoSomethingB()
{
}
I could simply write this:
pubilc void DoSomethingA(object sender,EventArgs e)
{
DoSomethingB();
DoSomethingC();
}
OnClick="DoSomethingA"
So here I call DoSomethingA on the onclick and in turn it then calls the other two functions DoSomthingB and DoSomethingC
Cheers
Andrew :-)
ASKER
I have done what you have said. I am now getting the following error message:
Compiler Error Message: CS1501: No overload for method 'CheckCredentials_Click' takes '0' arguments
Source Error:
Line 32: void multipleTask(object sender,EventArgs e)
Line 33: {
Line 34: CheckCredentials_Click();
Line 35: TemplatedEmailFormData();
Line 36: }
Compiler Error Message: CS1501: No overload for method 'CheckCredentials_Click' takes '0' arguments
Source Error:
Line 32: void multipleTask(object sender,EventArgs e)
Line 33: {
Line 34: CheckCredentials_Click();
Line 35: TemplatedEmailFormData();
Line 36: }
ASKER
????????????
I meant fo you to get that from my example, you simply need to place the other function call inside your original function for the button.
AddCredentials_Click(objec t sender, EventArgs e)
{
//YOUR CODE HERE!!
//NOW MY CODE
MailAddress FromAddress = new MailAddress("project@theid factor.com ");
MailAddress ToAddress = new MailAddress("project@theid factor.com ");
MailMessage message = new MailMessage(FromAddress, ToAddress);
message.Subject = "New Project Has been commissioned";
message.Body = txtPName.Text + 'Has now been commissioned';
SmtpClient client = new SmtpClient("127.0.0.1", 25);
client.Send(message);
//NOW ANY OTHER FUNCTION IF YOU WANT
AnotherFunctionOrTwoHere() ;
//NOW CLOSE THE FUNCTION BLOCK
}
AddCredentials_Click(objec
{
//YOUR CODE HERE!!
//NOW MY CODE
MailAddress FromAddress = new MailAddress("project@theid
MailAddress ToAddress = new MailAddress("project@theid
MailMessage message = new MailMessage(FromAddress, ToAddress);
message.Subject = "New Project Has been commissioned";
message.Body = txtPName.Text + 'Has now been commissioned';
SmtpClient client = new SmtpClient("127.0.0.1", 25);
client.Send(message);
//NOW ANY OTHER FUNCTION IF YOU WANT
AnotherFunctionOrTwoHere()
//NOW CLOSE THE FUNCTION BLOCK
}
p.s. make sure you know and insert the email provider host you have. replace the 127.0.0.1 with the actual email host address if it is not the same as that. i.e. a dedictaed server
ASKER
Im still having problem with the layout you have just showed me. The mail host i will sort that out later
Thanks
Thanks
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public partial class CreateProCom : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
void CheckCredentials_Click(Object s, EventArgs e) {
Response.Redirect("Default.aspx");
TemplatedEmailFormData();
{
MailAddress FromAddress = new MailAddress("project@theidfactor.com");
MailAddress ToAddress = new MailAddress("project@theidfactor.com");
MailMessage message = new MailMessage(FromAddress, ToAddress);
message.Subject = "New Project Has been commissioned";
message.Body = txtPName.Text + "Has now been commissioned";
SmtpClient client = new SmtpClient("127.0.0.1", 25);
client.Send(message);
}
}
}
void CheckCredentials_Click(Object s, EventArgs e) {
MailAddress FromAddress = new MailAddress("project@theidfactor.com");
MailAddress ToAddress = new MailAddress("project@theidfactor.com");
MailMessage message = new MailMessage(FromAddress, ToAddress);
message.Subject = "New Project Has been commissioned";
message.Body = txtPName.Text + "Has now been commissioned";
SmtpClient client = new SmtpClient("127.0.0.1", 25);
client.Send(message);
Response.Redirect("Default.aspx");
}
ASKER
I get this error now:
Compiler Error Message: CS0122: 'CreateProCom.CheckCredent ials_Click (object, System.EventArgs)' is inaccessible due to its protection level
Source Error:
Line 563:</asp:Table>
Line 564: <br />
Line 565:<asp:Button id="btnLogin" runat="server" Text="Print" onClick="CheckCredentials_ Click" Height="55px" Width="84px" />
Line 566:</form>
Line 567:</td>
Compiler Error Message: CS0122: 'CreateProCom.CheckCredent
Source Error:
Line 563:</asp:Table>
Line 564: <br />
Line 565:<asp:Button id="btnLogin" runat="server" Text="Print" onClick="CheckCredentials_
Line 566:</form>
Line 567:</td>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you!
I have made a quick example here for you. So say for any for you have, for the event of the submit button, either add this code or have it as the event handler. Basically it emnails you all the information from the posted form values prefixing with the name.
Cheers
Andrew
Open in new window