protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ }
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(SendMail("[email protected]", "[email protected]", "[email protected]", "Test Mail", "Test Mail Body"));
}
public string SendMail(string toList, string from, string ccList, string subject, string body)
{
MailMessage message = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
try
{
MailAddress fromAddress = new MailAddress(from);
message.From = fromAddress;
message.To.Add(toList);
if (ccList != null && ccList != string.Empty)
message.CC.Add(ccList);
message.Subject = subject;
message.IsBodyHtml = true;
message.Body = body;
smtpClient.Host = "mail.letrouters.com";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = true;
smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "xxxxx");
smtpClient.Send(message);
msg = "Successful";
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return msg;
}
Loading
Abhimanyu K VatsaPosted May 18, 2011, 8:23 AM
Look at this article to configure outlook (so that you can check your smtp, if works with outlook then will with asp):-
http://www.vbdotnetheaven.com/UploadFile/abhikumarvatsa/1472/
Gowtham manjuPosted May 19, 2011, 6:25 AM
Abhimanyu K VatsaPosted May 19, 2011, 4:17 AM
For this issue,
First, check out your smtp by contacting to hosting company's tech team. They will provide you the informations.
Second, post the sample codes that you will be using and getting errors.
Note: Sometimes smtp works on outlook but not on site mailing list, this could be an issue. This issue comes because of some authentication or say settings on mail server. Ask from Host Tech Team for this. Even you can ask for sample code from them. If they will not provide you then switch your host. Alternatively, you can use gmail or yahoo smtp, that's free.
Hope this helps.
Gowtham manjuPosted May 19, 2011, 2:37 AM
Abhimanyu K VatsaPosted May 19, 2011, 2:26 AM
do u think the code me and another members has given, is not sufficient? now asking for zipped.
Remember this is forum, and any forum provide milk and rice only....that's your job to make (cook) it kheer.
Gowtham manjuPosted May 19, 2011, 1:46 AM
Abhimanyu K VatsaPosted May 19, 2011, 1:19 AM
If so, then you have to create (configure) your smtp here too, this also requires the smtp. If you have, create some functions in code-behind which inserts the user details (id, pass, etc) to database and call another function to send the mail containing his infos. Here you go...
protected void submit_Click(object sender, EventArgs e)
{
execution(); //this function will insert the record (id, pass etc in db) and send the mail too.
}
public void execution()
{
//place the sql insert methods there
sendmail(fullname, emailid, username, password);
}
public void sendmail(string fullname, string emailid, string username, string password)
{
string smsg = "New Registration:
";
smsg += "
Name: " + fullname;
smsg += "
Username: " + username;
smsg += "
Password: " + password;
smsg += "
";
smsg += "Administrator";
MailMessage message = new MailMessage();
try
{
message.To.Add(new MailAddress(emailid));
message.From = new MailAddress("[email protected]");
message.Subject = "New Registration";
message.Body = smsg;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Port = 587; // Gmail works on this port 587
client.Host = "smtp.gmail.com";
System.Net.NetworkCredential nc = new System.Net.NetworkCredential("[email protected]", "password");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = nc;
client.Send(message);
}
catch
{
//place the catch statements here
}
}
Place any url for verification in your mail or you may send any random number in email and ask the user to verify using that number.
Hope this helps
Suthish NairPosted May 18, 2011, 1:49 PM
Gowtham manjuPosted May 18, 2011, 9:01 AM
Abhimanyu K VatsaPosted May 18, 2011, 8:37 AM
Gowtham manjuPosted May 18, 2011, 8:25 AM
Gowtham manjuPosted May 18, 2011, 8:21 AM
Gowtham manjuPosted May 18, 2011, 8:16 AM
Abhimanyu K VatsaPosted May 18, 2011, 8:12 AM
Gowtham....it is still working live for my many customers. I recommend you to check out your smtp using outlook before proceeding.
Gowtham manjuPosted May 18, 2011, 7:45 AM
Abhimanyu K VatsaPosted May 18, 2011, 7:34 AM
find the sample code working for me (i'm using gmail here):-
//constructing html based email
";
Test: " + abc;
Test: " + xxx;
Test: " + abx;
";
Now call this function as
sendmail(a.Text, b.Text, c.Text);
Posted May 18, 2011, 7:24 AM
Gowtham manjuPosted May 18, 2011, 6:31 AM
Posted May 18, 2011, 6:26 AM
And check SMTP server is installed on the 174.133.162.186 machine.
Gowtham manjuPosted May 18, 2011, 6:23 AM
============================================================================================ System.Net.Mail.SmtpException was caught Message="Failure sending mail.
" Source="System" StackTrace: at System.Net.Mail.SmtpClient.Send(MailMessage message)
at mail2.SendMail(String toList, String from, String ccList, String subject, String body)
in c:\Documents and Settings\Administrator\Desktop\mail\mail2.aspx.cs:
line 44 InnerException: System.Net.WebException Message="Unable to connect to the remote server" Source="System" StackTrace: at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) InnerException: System.Net.Sockets.SocketException Message="No connection could be made because the target machine actively refused it 174.133.162.186:25" Source="System" ErrorCode=10061 NativeErrorCode=10061 StackTrace: at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) InnerException: ============================================================================================
Posted May 18, 2011, 6:09 AM