Sending Email- not working.

Posted by Gayathri under ASP.NET on 5/16/2011 | Points: 10 | Views : 1779 | Status : [Member] | Replies : 3

Can someone help me with the email code in Csharp and

Please donot post any general forums other than dotnet funda solutions.

I have referred so many sites and none of them are working for me.

My objective is

1)donot hardcode the from address,from password
2)donot hardcode the to address ,to password
3)It should be in global usage.
for example, suppose if i say as from add
and it should work.

similarly to
should work.

please let me if this is possible in

I will be much thankful for early responses.


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

public void sendEmail()
MailMessage msg = new MailMessage();
msg.From = new MailAddress("","Susan");
msg.To.Add(new MailAddress(""));
msg.Subject = "Sending Email from webapplication";
msg.Body = "Type your Email Content here";
SmtpClient client = new SmtpClient();
client.Host = "Give your mail server IP";
client.Port = Put port number;


use this simple method.


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

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

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

End Sub

Call That Function :-

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)


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

Login to post response