Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi guys,

I am very new in asp.net , now i am working for asp.net project . please any one send the code how to send mail through asp.net
Posted
Comments
koolprasad2003 29-Jul-11 8:32am    
It's very easy some Googling will give u answer.

That is one of does Questions that is stuck on repeat.
But check this out Sending an Email in C# with or without attachments: generic routine.[^] and Using Gmail Account to Send Emails With Attachment[^]
 
Share this answer
 
Refer to this[^]. It has complete code which will surely help you!
 
Share this answer
 
v2
Hi, use this

Import
VB
Using System.Web.Mail


C++
MailMessage msg = new MailMessage();

msg.To = "das@silicomm.com";
msg.From = "das@aspalliance.com";
msg.Subject = "test";
//msg.BodyFormat = MailFormat.Html
msg.BodyFormat = MailFormat.Text;
msg.Body = "hi";

msg.Attachments.Add(new MailAttachment(Server.MapPath("EMAIL1.ASPX")));

SmtpMail.SmtpServer = "localhost";

SmtpMail.Send(msg);
msg = null;

lblMsg.Text = "An Email has been send to " + "das@silicomm.com";


:)
 
Share this answer
 
u can use it

before using u can have valid gmail which use for NetworkCredentialcaditin
VB
Public Sub SendMail(ByVal UserName As String, ByVal Pwd As String, ByVal From As String, ByVal To1 As String, ByVal Subject As String, ByVal Body As String)


       Dim mailPath As New System.Net.NetworkCredential(UserName, Pwd)
       Dim client As New SmtpClient("smtp.gmail.com", 587)
       client.Credentials = mailPath
       client.EnableSsl = True

       Dim SendFrom As New MailAddress(From)
       Dim SendTo As New MailAddress(To1)



       Dim MyMessage = New System.Net.Mail.MailMessage(SendFrom, SendTo)

       MyMessage.Subject = Subject
       MyMessage.Body = Body
       MyMessage.DeliveryNotificationOptions=DeliveryNotificationOptions.OnFailure



       client.Send(MyMessage)

       lblMsg.Text = "Your message has been sent successfully To:- " & "," & To1

   End Sub

'this is function that use 

   Protected Sub btnSendmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSendMail.Click

       'Dim strEmailIDList As String = ""
       'Dim Success As Boolean = True
       Try
           Dim Username As String = Session("EmailID")
           Dim Pwd As String = Session("Password")
           Dim From As String = Session("EmailID")
           Dim To1 As String = Session("Email")
           'Dim cc As String = txtCC.Text
           Dim Subject As String = txtSubject.Text
           Dim Body As String = txtBody.Text

           SendMail(Username, Pwd, From, To1, Subject, Body)


       Catch ex As Exception
           lblMsg.Text = "The message could not be sent" + ex.Message
       End Try
   End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900