sending email code - correction required

Posted by Gayathri under ASP.NET on 5/18/2011 | Points: 10 | Views : 1977 | Status : [Member] | Replies : 7
hi,

The following code does not work for me.
i tried specifying the from user id and password too.
even then nothing is working out.

Kindly help. please correct the code.



protected void Button1_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();

msg.From = new MailAddress(TextBox1.Text);
msg.To.Add(TextBox2.Text);
msg.Subject = TextBox3.Text;
msg.Body = TextBox4.Text;

SmtpClient Client = new SmtpClient("smtp.gmail.com");
Client.EnableSsl = true;

Client.Port = 25;
Client.Send(msg);
Response.Write("Mail sent");




}




Responses

Posted by: Vuyiswamb on: 5/18/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
look at the part i do the email
http://www.dotnetfunda.com/articles/article1074-how-to-send-an-email-in-silverlight-part-1-.aspx

Thank you for posting at Dotnetfunda
[Administrator]

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

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

Up
0
Down
Hi Gayathri,
Refer this...
http://www.dotnetfunda.com/Blogs/Susanthampy/1547/sending-email-from-aspnet-webapplication
Thanks

Nitha Deepak

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

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

Up
0
Down
change msg.To.Add(TextBox2.Text); as
msg.To.Add(new MailAddress(TextBox2.Text));

Thanks
Lokesh Kumar

Gayathri, 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
Refer this,

http://msdn.microsoft.com/en-us/library/ss6zhx82(vs.71).aspx



Regards,
Susan

Gayathri, 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
Refer This,

http://msdn.microsoft.com/en-us/library/ss6zhx82(vs.71).aspx

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
try this will help 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

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

Posted by: Ksuresh on: 6/25/2012 [Member] Starter | Points: 25

Up
0
Down
hi every one,

mailname@mydomain.com in this email id , incoming emails from mydomain.com are directly going to Trash folder, i want emails in to the inbox .. Please any one help me in this.

Regards
Suresh

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

Login to post response