473,378 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

sending mail using smtp

1
MailMessage email=new MailMessage();
email.To=to.Text;
email.From=from.Text;
email.Subject=sub.Text;
email.Body=msg.Text;
try
{ SmtpMail.Send(email);
SmtpMail.SmtpServer="localhost";
}
catch
{}
this is the code i used. but didnt work. is there anything more to b added
Feb 8 '07 #1
3 1393
hai,
this is the code for sending mail in asp.net with vb

Dim objEmail As New Mail.MailMessage
objEmail.BodyFormat = Mail.MailFormat.Html
objEmail.To = ""
objEmail.From = ""
objEmail.Subject = ""
objEmail.Body = "Dear ,"
objEmail.Body += "<br> <br>"
objEmail.Body += " "
objEmail.Body += ""
objEmail.Body += ""
objEmail.Body += "This is autogenerated mail delete this message"
objEmail.Priority = Mail.MailPriority.High
Try
Mail.SmtpMail.Send(objEmail)


Catch exc As Exception
Response.Write("Send failure: " + exc.ToString())
End Try

In the above code i have used the bodyformat as html to include the html tags other wise use the text format.
This is the code i have used and it is working fine. convert it into C# and use it
Feb 8 '07 #2
hi,
Im sorry the above code is the same as urs but i think that u have to check whether smtp is running or not
Feb 9 '07 #3
hi,
htis is the code
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Mail" %>
<script runat="server">

void btnSubmit_Click(Object sender, EventArgs e) {

MailMessage objEmail = new MailMessage();
objEmail.To = txtTo.Text;
objEmail.From = txtFrom.Text;
objEmail.Cc = txtCc.Text;
objEmail.Subject = "Test Email from the Article Working with Email using ASP.NET - Part 1";
objEmail.Body = txtName.Text + ", " +txtComments.Text;
objEmail.Priority = MailPriority.High;
objEmail.BodyFormat = MailFormat.Html;

// Make sure you have appropriate replying permissions from your local system
//SmtpMail.SmtpServer = "localhost";

try{
SmtpMail.Send(objEmail);
Response.Write("Your Email has been sent sucessfully - Thank You");
}
catch (Exception exc){
Response.Write("Send failure: " + exc.ToString());
}
}
</script>

<html>
<head>
<title>E-mail and ASP.NET - Part 1</title>
</head>
<body>
<form runat="server">
<div align="left">
<table border="0" width="350">
<tr>
<td valign="top"><font face="Verdana" size="2">Name:</font></td>
<td height="24"> <asp:TextBox runat="server" Height="25px" Width="215px" ID="txtName"></asp:TextBox>
<br>
<asp:RequiredFieldValidator ID = "req1" ControlToValidate = "txtFrom" Runat = "server" ErrorMessage = "Please enter your name"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td valign="top"><font face="Verdana" size="2">From</font></td>
<td height="24"> <asp:TextBox runat="server" Height="22px" Width="213px" ID="txtFrom"></asp:TextBox>
<br>
<asp:RegularExpressionValidator ID = "reg1" ControlToValidate = "txtFrom" Runat = "server" ErrorMessage = "Invalid Email" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>&nbsp;<asp:Required FieldValidator ID = "req3" ControlToValidate = "txtFrom" Runat = "server" ErrorMessage = "Please enter your E-mail" ></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td valign="top"><font face="Verdana" size="2">To</font></td>
<td height="24" valign="top">
<asp:TextBox runat="server" Height="22px" Width="212px" ID="txtTo"></asp:TextBox>
<br>
<asp:RegularExpressionValidator ID = "reg2" ControlToValidate = "txtTo" Runat = "server" ErrorMessage = "Invalid Email" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
&nbsp;<asp:RequiredFieldValidator ID = "req4" ControlToValidate = "txtTo" Runat = "server" ErrorMessage = "Please enter recipients E-mail" ></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td valign="top"><font face="Verdana" size="2">Cc</font></td>
<td height="24" valign="top">
<asp:TextBox runat="server" Height="22px" Width="210px" ID="txtCc"></asp:TextBox>
<br>
<asp:RegularExpressionValidator ID = "reg3" ControlToValidate = "txtCc" Runat = "server" ErrorMessage = "Invalid Email" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
</tr>
<tr>
<td valign="top"><font face="Verdana" size="2">Comments:</font></td>
<td height="112"> <asp:TextBox runat="server" Height="107px" TextMode="MultiLine" Width="206px" ID="txtComments"></asp:TextBox>
<br>
<asp:RequiredFieldValidator ID = "req2" ControlToValidate = "txtComments" Runat = "server" ErrorMessage = "Please enter your comments"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2" valign="top" height="30">
<p align="center">


<asp:Button Runat = server ID = btnSubmit OnClick = btnSubmit_Click Text = "Submit"></asp:Button>
&nbsp;<input type = "reset" runat = "server" value = "Clear"></td>
</tr>
</table>
</div>

<p>&nbsp;</p>
<p><br>


<!-- Insert content here -->
</p>
</form>
</body>
</html>
Feb 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Sven Templin | last post by:
Hello all, our configuration is as following described: - OS: Windows 2000 - Apache server 1.3 - Php 3.8 - MS outlook client 2000 _and_ no SMTP server available in the whole intranet.
13
by: joe215 | last post by:
I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using...
8
by: Frank | last post by:
I think I've confused myself completely here :-) I have used System.Web.Mail, but am not sure if this works with Exchange Server 5.5. I asked the client if they're email server supported SMTP, and...
9
by: B-Dog | last post by:
I've built a small app that sends mail through our ISP's SMTP server but when I try to send through my local exchange server I get CDO error. Does webmail use SMTP or does it strictly rely on...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
3
by: armando perez | last post by:
Hi, this is my first time here, but I was looking for something that may help me, and still, I haven't found something to use. I'm using a website made in .NET with C#, when I'm running my site...
8
by: Mike Owen | last post by:
Hi, I am using the following code to send email on a Windows 2003 Web Server: Imports System.Net.Mail ........ Dim msgmail As New MailMessage msgmail.To.Add(New...
8
by: Robert Dufour | last post by:
Dim message As New MailMessage("mymail@mydomain.com", "mymail@mydomain.com", "Test", "Test") Dim emailClient As New SmtpClient("localhost") emailClient.Send(message) The IIS server is...
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
31
by: happyse27 | last post by:
Hi All, I am trying for weeks how to send email from windows pc, which from my gmail account to my hotmail account. Using net::smtp module sending email failed,Kindly assist. (for the item d it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.