Problem on Sending E-mail
I wish to incorporate e-mail in my page such that when a user had pressed a button, an email will be sent to the recipient. This has been my code.
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.BodyFormat = MailFormat.Html;
mail.Body = "this is my test email body.<b>this part is in bold</b>";
SmtpMail.SmtpServer = "localhost"; //your real server goes here
SmtpMail.Send( mail );
When I had uploaded the page in my site I received this error:The transport failed to connect to the server.
and the error is pointed to the statement SmtpMail.SmtpServer = "localhost";
What is the problem in my code?
ebabes
Junior Poster in Training
73 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
you need an SMTP mail server, andyour local host isn't it :)
find out which is yours, if you have one, and put the address there.
Most hosted domains have mail.domainname.com as there smtp server.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
Thanks SheSaidImaPregy! Can you answer my problem on Calendar please. I want that when a user clicks a date in a calendar, a message in a textbox will appear and let's assume that it is a scheduled meeting. Thanks. I badly need the answer please.
ebabes
Junior Poster in Training
73 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
You can do it through AJAX, Javascript, or to stick with ASP.NET, just changed the onselected change event to call a sub like below:
Sub caldate(s as object, e as eventargs)
If Page.IsPostBack Then
tbDate.Text = Calendar1.SelectedDate.ToShortDateString()
End If
End Sub
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
Thanks SheSaidImaPregy! The code is great. I just want to know from empkeydotcom if how can I set it as my mail server in my code. Assume that I have an email account as ebabes@gmail.com. I badly need the code for this. Thanks and more power!
ebabes
Junior Poster in Training
73 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
ebabes
Junior Poster in Training
73 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
You need to specify your SMTP server there. Meaning, you need to put the IP Address or the domain name.
What it is telling you is that "smtpServer" is not set or declared on the page, so when reading it, it doesn't do anything.
You can, if you wish, declare the variable as follows:
Dim smtpServer As String = "mail.mydomain.com"
Or whatever your smtpserver address is.
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68