Library tutorials & articles
SMTP Mailing Application
- Introduction
- Getting Started
- The Code
Introduction
This is an article on how to use the Mail Components in .NET to create a simple application to send e-mail.
Figure 1 - The Smtp Mailing Application
The Smtp Mail functionality is contained in the System.Web.Mail namespace and contains three classes:
Table 1 - System.Web.Mail Namespace
| System.Web.Mail Classes | Description |
| SmtpMail | Class used to send Mail via Windows 2000 SMTP services |
| MailMessage | This class contains everything contained in an e-mail message. An instance of this can be sent by the SmtpMail class |
| MailAttachment | This is a class representing an attachement to an email. |
The SmtpMail Class gives you two static methods to send mail: the quick and easy way, and the more detailed way.
SmtpMail.Send(FromString, ToString, SubjectString, MessageString)
or
SmtpMail.Send(aMailMessage)
I opted to send email using the MailMessage object in this example because you can send a lot more information. Some of the properties of the MailMessage Object are shown below:
|
MailMessage Property |
Description |
| From | who the email is from |
| To | who the email is to |
| Cc | who the email is copied to |
| Bcc | who the email is copied to without seeing the recipients |
| Attachments | A collection of Attachments to the email |
| Subject | Subject of the email |
| Body | Message Body of the email |
| BodyFormat | The format of the Message Body (Currently Text or Html) |
| Priority | MailPriority of the Message (High, Low, or Normal) |
Table 2 - MailMessage Properties for an E-mail Message
Related articles
Related discussion
-
google apps email using php
by lghtyr (0 replies)
-
House Of Representatives Email Addresses, Antonio House San
by JeremyS (0 replies)
-
Email Servers For Dummies, Application Building Knowledge Microsoft Portal Server Sharepoint Sharing
by JamesO (0 replies)
-
Career Builder Monkey Email, Las Vegas Rental Cars For Sale
by Alexjj (0 replies)
-
Buy cheap Xanax overnight. Cheap Xanax. Overnight delivery of Xanax in US no prescription needed. Cheapest Xanax.
by asleymar (0 replies)
Related podcasts
-
Object-Oriented Programming in Ruby
In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...
I found a very simple (and flexible) .NET Mail API. Check out EZ E-Mail .NET API @ http://www.get-a-code-monkey.com/MailProcessor.aspx
Though, it may have limited functionality it's REALLY easy to use. They have example which make using it VERY simple.
!--removed tag-->Hi prazathin
Not at all, good days
hi cicada
Thank u
and aspx page html part <%@ Import Namespace="System.Web.Mail" %>
ok?
<script runat="server">
Sub MailGonder(Sender As Object, E As EventArgs)
Dim NewMail As New MailMessage()
NewMail.From = txtfrom.text
NewMail.To = "mail@mail.com.tr"
NewMail.Subject = txtsubject.text
NewMail.Body = txtmessage.text
SmtpMail.SmtpServer = "smtpservername"
SmtpMail.Send(NewMail)
Response.Write("Mail successfully")
Response.End
End Sub
</script>
<script runat="server">
Sub clean(Sender As Object, E As EventArgs)
txtFrom.text=""
txtSubject.text=""
txtMessage.text=""
End Sub
</script>
I was trying to send mail through SMTP in vb.net..I was not able to import system.web.mail namespace.Do i have to install anything for this..
hi, I'm an ASP.Net developer, i need to create a table in my sqlserver dyanmically by sending the values from a textbox from my asp application, can u help me to get going
,u can contact me in chezhian_in05@rediffmail.com.
Hi guys,
I am using email in my app and using attchments as well. Does anybody knows how to load the icon of the attached document instead of whole path in a text box and place it in a picture box ?
Thanks
Mehrdad
Hi guys,
I am using email in my app and using attchments as well. Does anybody knows how to load the icon of the attached document instead of whole path in a text box and place it in a picture box ?
Thanks
Mehrdad
Thanks. Its working.
Regards,
PremLatha.
Mehrdad
It works.
Mehrdad
Thanks & Regards,
PremLatha.
System.Web.Mail.SmtpMail.SmtpServer = MailServer; // SMTP Server IP
MailMessage mailMessage = new MailMessage();
//Set the SMTP Authentication details
mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpa
uthenticate", "1"); //basic authentication
mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendu
sername", MailUserID ); //set your username here
mailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendp
assword", MailPassword ); //set your password here
System.Web.Mail.SmtpMail.Send(mailMessage);
Nitin Chaudhary
Email: nitin_chaudhary@yahoo.com
I know this makes little to no sense, but I too had the exact code working on a .Net app and it too studdenly stopped working.
One simple line fixed it, reasons unknown, just try this....
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 60)
The default value for smtp connection timeout is 30 seconds. I just beefed up that part. I guess 30 seconds wasn't enough for all SMTP connection (incl. name resolution, user authentication, etc. ).
Hope this helps,
Brian
brian.pressman@iko.com
Hi Guys, can u help with some web sites that i can visit to learn more about .Net platform.
Cheers
TK
Hi guys,
I also have the same problem and REALLY don't know how to come over it. You may have found the solution for it yet I just got it. Could you guys help me too?
YOu may also contact me directly : mehrdada@shaw.ca
Thanks
Mehrdad
This article is great! I'm very impressed as a .NET newbie.
I send 3 messages to myself at interval of 5 minutes. all three of them arrived about 45 minutes later.
How does the method work? Does it queue up a certain number of message & send them at same time. Is there a way to send the mail messages instantly?
puzzled!
Hi,
I have tried to send the email similar to what you have done, with the exception of specifying the SmtpMail.SmtpServer.
But when I try to send an email there is an exception that says (Could not create 'CDO.Message' object ) . Can you help me out with this?
thank you.
Swetha
Hello;
thank you for your work.
but when i tried to send an email there was an exciption that say (could not acess 'CDO.Message' object )
so what can i do??
thank you.
Younis Alomoush
Because, I am a Vietnanese, so my English quite poor.
I think that, when a source to send a message, we need a host mail to send, but in this source code, I can't see about any host.
I tried to send a message, but I can't receive a message which I send.
Thank a lot.
Nguyet Anh.
If SmtpServer property is not set, the name of the local SMTP server is used. Set SmtpServer property of the SmtpMail class (Assign IP address) to make it work over the internet.
have the CDO dlls installed (registered).
If you don't want this route, try to
create your own mail compnent. I refer
you to search google for 'smtp mail component in c#'.
This code works great on my development machine.
MailMessage myMail = new MailMessage();
myMail.From = "me@yahoo.com";
myMail.To = "hardware@yahoo.com";
myMail.Subject = EmpCurrent.WholeName + " Has sent Purchase
Requisition #" + lblReqNumber.Text + " to you for your review.";
myMail.Priority = MailPriority.Normal; myMail.BodyFormat = MailFormat.Html;
myMail.Body = "Please review and reject or approve as soon as possible.";
SmtpMail.Send(myMail);
But when I install it on a desktop, it gives the following message every time:
Any Ideas?
Here is the error message:
*** Exception Text ***
System.Web.HttpException: Could not create 'CDONTS.NewMail' object.
at System.Web.Mail.LateBoundAccessHelper.get_LateBoundType()
at System.Web.Mail.CdoNtsHelper.Send(MailMessage message)
at System.Web.Mail.SmtpMail.Send(MailMessage message)
at PerfectReqs.PerfectReq.MenuActionSubmitOnClick(Object sender,
EventArgs e)
at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
at System.Windows.Forms.MenuItemData.Execute()
at System.Windows.Forms.Command.Invoke()
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
This thread is for discussions of SMTP Mailing Application.