how to make mail scipts in c#?

Posted by Tushar under C# on 3/5/2009 | Views : 3852 | Status : [Member] | Replies : 2
Dear VUYISWA JUNIUS
I hope now my English is Good.
I hope u Understand my question.
Have nice day.
Thank You...




Responses

Posted by: perfectchourasia-9163 on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
http://sandeep-chourasia.blogspot.in/2011/05/send-mail-in-aspnet.html

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Tushar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 3/5/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
hi Tushar

The English is better now. Here is how its done in C# and ASP.NET using C#

In ASP.NET, sending emails has become simpler. The classes required to send an email are contained in the System.Net.Mail. The steps required to send an email from ASP.NET are as follows :

Step 1: Declare the System.Net.Mail namespace
C# -
 using System.Net.Mail;

VB.NET - Imports System.Net.Mail

Step 2: Create a MailMessage object. This class contains the actual message you want to send. There are four overloaded constructors provided in this class. We will be using

C# -
 public MailMessage ( string from, string to, string subject, string body )


VB.NET -

 public MailMessage (String From, String to, String subject, String body)


The constructor of this MailMessage class is used to specify the sender email, receiver email, subject, body.
C#
MailMessage message = new MailMessage            ("abc@somedomain.com","administrator@anotherdomain.com","Testing","This is a test mail");

VB.NET
Dim message As MailMessage = New MailMessage ("abc@somedomain.com","administrator@anotherdomain.com","Testing","This is a test mail")


Step 3: To add an attachment to the message, use the Attachment class.

C#
string fileAttach = Server.MapPath("myEmails") + "\\Mypic.jpg";

Attachment attach = new Attachment(fileAttach);
message.Attachments.Add(attach);


VB.NET
Dim fileAttach As String = Server.MapPath("myEmails") & "\Mypic.jpg" 

Dim attach As Attachment = New Attachment(fileAttach) message.Attachments.Add(attach)


Step 4:After creating a message, use the SmtpClient to send the email to the specified SMTP server. I will be using 'localhost' as the SMTP server.

C#
SmtpClient client = new SmtpClient("localhost");

client.Send(message);


Additionally, if required, you

client.Timeout = 500; 

// Pass the credentials if the server requires the client to authenticate before it will send e-mail on the client's behalf.
client.Credentials = CredentialCache.DefaultNetworkCredentials;


VB.NET

Dim client As SmtpClient = New SmtpClient("localhost") 

client.Send(message)


Additionally, if required, you client.Timeout = 500

' Pass the credentials if the server requires the client to authenticate before it will send e-mail on the client's behalf.

client.Credentials = CredentialCache.DefaultNetworkCredentials 


That's it. It's that simple.
To configure SMTP configuration data for ASP.NET, you would add the following tags to your web.config file.

 <system.net>

<mailSettings>
<smtp from="abc@somedomain.com">
<network host="somesmtpserver" port="25" userName="name" password="pass" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>


References :
[u]http://msdn2.microsoft.com/En-US/library/system.net.mail.mailmessage.aspx[/u]

Or another way is here

http://www.asp.net/learn/Videos/video-420.aspx


http://www.codeproject.com/KB/IP/email.aspx

http://www.codeproject.com/KB/IP/emailsender2.aspx


http://www.codeproject.com/KB/vb/SendMail.aspx

Hope it Helped

Thank you for posting at Dotnetfunda
[Administrator]

Tushar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response