Sending Email- not working.

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

Can someone help me with the email code in Csharp and asp.net?

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 yamini@yahoo.com as from add
and deepa@gmail.com it should work.

similarly yamini@somedomain.com to keerthi@somedomain.com.
should work.

please let me if this is possible in asp.net.

I will be much thankful for early responses.




Responses

Posted by: Nithadeepak on: 5/16/2011 [Member] Bronze | Points: 25
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);

}

use this simple method.

Regards,
Susan

Gayathri, 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
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 :-

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

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

Login to post response