Library tutorials & articles
SMTP Mailing Application
- Introduction
- Getting Started
- The Code
The Code
Next we design our mail application by placing textboxes for From, To, Copy, Blind Copy, Subject, Attachment, and the Message Body. We then add corresponding labels for each of the textboxes. Also, we add a button for sending the message and a button to exit the application. As an added feature, we placed a browse button next to the attachment so we can browse for attachments on our file system. The browse button uses the OpenFileDialog component for navigating for an attachment (as seen at the bottom of the designer.)
Figure 5 - E-Mail Sender Design View
Below is the code used to send the email we construct in our form. The code is executed in the SendButton_Click Event Handler. The method simply creates a new MailMessage instance and populates it with the text typed into the various fields by the user. The MailMessage object is then sent using the SmtpMail.Send static function:
Listing 2 - Send Button Event Handler
private
void
SendButton_Click(object sender, System.EventArgs
e)
|
Below is the button event handler for populating the Attachment
field through the Browse button.
It simply calls ShowDialog on the OpenFileDialog instance and if the result is
ok it assigns the filename chosen by the user to the attachment field:
Listing 3 - Browse Button Event Handler
private
void
BrowseButton_Click(object sender, System.EventArgs
e)
|
I suspect you'd be more likely to use Microsoft Outlook then this simple application, but you can utilize the code in this application to customize it to suit your specific needs. For example, you might consider creating a database in access and writing C# and ADO.NET for accessing groups of people you'd like to send emails. You could change this into a component and have it pop up when you need to send emails in your application. In any case, this will get you started in your quest to send emails using .NET.
Related articles
Related discussion
-
google apps email using php
by lghtyr (0 replies)
-
C# video Editing/rendering
by pkuchaliya (0 replies)
-
How to Fill DataSet with more records (around 1 lakh) in a faster way
by Jayaram P (0 replies)
-
Can't print on the network with MSADESS ??
by anatha1 (2 replies)
-
How to POP3 in C#
by converter2009 (9 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.