Mail sending function in ASP.net web page.

Posted by Gokul under Regular Expressions on 5/13/2011 | Points: 10 | Views : 10520 | Status : [Member] | Replies : 5
Dear Friends
I am developing a application where i want to send mails to the users. I want to know how to create a mail sending function in ASP.net application. If i get a step by step article to develop this requirement , then it will be a helpful note for me to develop my konwledge.

Thanks and Regards,
GokulNath Nithy.



Responses

Posted by: Nithadeepak on: 5/13/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,
Refer the below link...
http://www.dotnetfunda.com/Blogs/Susanthampy/1547/sending-email-from-aspnet-webapplication
Hope this helps you...
Thanks,

Nitha Deepak

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

Posted by: Prabhakar on: 5/13/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Gokul


i am talk about sending mail in my article . . read it . . it's help us u . .


http://www.dotnetfunda.com/articles/article1162-import-gmail-contacts-in-gridview-and-send-mail-to-selected-email-ids-.aspx

Best Regard's
Prabhakar

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

Posted by: Susanthampy on: 5/19/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
public void sendEmail()
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("susanthampy@gmx.com","Susan");
msg.To.Add(new MailAddress("sreelass@gmail.com"));
msg.Subject = "Sending Email from Asp.net webapplication";
msg.Body = "Type your Email Content here";
SmtpClient client = new SmtpClient();
client.Host = "Give your mail server IP";
client.Port = Put port number;
client.Send(msg);

}

Regards,
Susan

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

Posted by: Prafullshrivastava on: 5/19/2011 [Member] Starter | Points: 25

Up
0
Down
try this it is helpful for you:-

Create a function:-

Public Shared Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal subject As String, ByVal body As String)
' Instantiate a new instance of MailMessage
Dim mMailMessage As New MailMessage()

' Set the sender address of the mail message
mMailMessage.From = New MailAddress(from)
' Set the recepient address of the mail message
mMailMessage.To.Add(New MailAddress(recepient))
' Set the subject of the mail message
mMailMessage.Subject = subject
' Set the body of the mail message
mMailMessage.Body = body

' Set the format of the mail message body as HTML
mMailMessage.IsBodyHtml = True
' Set the priority of the mail message to normal
mMailMessage.Priority = MailPriority.Normal

' Instantiate a new instance of SmtpClient
Dim mSmtpClient As New SmtpClient()
' Send the mail message
mSmtpClient.Send(mMailMessage)

End Sub

Call That Function :-

dsResetPassword = objSAMService.ResetPassword(EmailId)
dtResetPassword = dsResetPassword.Tables(0)
Dim recep As String
Dim from as String
Dim body As String
Dim pass As String
Dim subject As String

from = dtResetPassword.Rows(0)("SenderName")
recep = dtResetPassword.Rows(0)("UserName")
pass = dtResetPassword.Rows(0)("Password")
body = "Your New Password Is" + " " + pass
subject = "Reset Password"

SendMailMessage(from, recep, subject, body)
ClientScript.RegisterStartupScript(Me.GetType(), Guid.NewGuid().ToString(), "alert('Your Mail Send Successfully');", True)


Pshrivastava

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

Posted by: ttarakarajesh-8732 on: 8/30/2011 [Member] Starter | Points: 25

Up
0
Down
The following code may helpful to you to send an email from asp.net

protected void btnSend_Click(object sender, EventArgs e)
{
SmtpClient smtpclient = new SmtpClient();
System.Net.Mail.MailMessage mailMsg = new System.Net.Mail.MailMessage();

MailAddress mailAddress = new MailAddress(txtFrom.Text, "put sender name here", System.Text.Encoding.UTF8);

mailMsg.From = mailAddress;
mailMsg.To.Add(txtTo.Text);
mailMsg.CC.Add(txtCC.Text);

mailMsg.Body = txtMessage.Text ;
smtpclient.Credentials = new System.Net.NetworkCredential(txtFrom.Text, txtPassword.Text);
smtpclient.Host = "smtp.gmail.com";
smtpclient.Port = 25;
smtpclient.EnableSsl = true;

try
{
smtpclient.Send(mailMsg);
txtFrom.Text = txtTo.Text = txtPassword.Text=txtCC.Text = txtMessage.Text = string.Empty;
Response.Write("Your Email has been sent successfully - Thank You");
}

catch (Exception ex)
{
lblErrorMessage.Text = ex.Message;
}
}

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

Login to post response