Click here to Skip to main content
16,016,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to send message to any other email id ex emailidremoved@gmail.com from asp.net page.
kindly send c# code and .aspx


[Edited]EmailID is removed[/Edited]
Posted
Updated 16-Nov-11 20:56pm
v3
Comments
RaviRanjanKr 17-Nov-11 2:57am    
A suggestion :- Never use your EmailID in any case by any way. :)

There is no difference sending mails out of ASPNET or any other .NET program

web.config:
Quote:

<configuration>
<appsettings>
<add key="MailServer" value="mail.codx.ch">
<add key="MailServerPort" value="25">
<add key="MailLoginUser" value="UserId">
<add key="MailLoginUserPw" value="Password">
<add key="MailSender" value="account@server.ch">
<add key="MailReceiver" value="receiver@server.ch">



using System;
using System.Net;
using System.Net.Mail;
using System.Configuration;
using System.IO;

Quote:
TextWriter tw = new StreamWriter("c:\\temp\\Mailtest.txt");
try
{
string myMailServer = ConfigurationManager.AppSettings["MailServer"].ToString();
int myMailServerPort = Convert.ToInt32(ConfigurationManager.AppSettings["MailServerPort"].ToString());
string myMailAccount = ConfigurationManager.AppSettings["MailLoginUser"].ToString();
string myMailPassword = ConfigurationManager.AppSettings["MailLoginUserPw"].ToString();
string myMailSender = ConfigurationManager.AppSettings["MailSender"].ToString();
string myMailReceiver = ConfigurationManager.AppSettings["MailReceiver"].ToString();

SmtpClient client = new SmtpClient(myMailServer, myMailServerPort);
client.Credentials = new NetworkCredential(myMailAccount, myMailPassword);


using (MailMessage msg = new MailMessage())
{
string myCurTime = System.DateTime.Now.ToString();
msg.From = new MailAddress(myMailSender);
msg.Subject = "Server :'" + System.Environment.MachineName + "' " + myCurTime;

msg.Body = "Message :" + myCurTime;

//msg.Attachments.Add(new Attachment("c:\\test.txt", "text/plain"));
//msg.Attachments.Add(new Attachment("C:\\test.exe", "application/octet-stream"));

msg.To.Add(new MailAddress(myMailReceiver));
client.Send(msg);
}
}
catch (Exception myEx)
{
// write a line of text to the file
tw.WriteLine(DateTime.Now + myEx.Message);
tw.WriteLine(myEx.Source);
tw.WriteLine(myEx.StackTrace);

}
finally
{
// close the stream
tw.Close();
}
 
Share this answer
 
There is a generic routine for doing that here: Sending an Email in C# with or without attachments: generic routine.[^]
 
Share this answer
 
Try
Send Email in ASP.Net 2.0 - Feed back Form[^]
or have a look there-CP Search-[send email in asp.net][^] to get many more question with plenty of links and solutions asked in CP regarding about Sending Email.
 
Share this answer
 
v2
There are alredy lot of answers for this question see
Google

or check this method
C#
public static Boolean SendingMail(string From, string To, string Subject, string Body)
    {
        
            try
            {
                MailMessage m = new MailMessage("Test<sender@gmail.com>", To);
                m.Subject = Subject;
                m.Body = Body;
                m.IsBodyHtml = true;
                m.From = new MailAddress(From);
 
                m.To.Add(new MailAddress(To));
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "mail.google.com";
              
                NetworkCredential authinfo = new NetworkCredential("test@gmail.com", "te1234");
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = authinfo;
                smtp.Send(m);
                return true;
 
               
 
 
            }
            catch (Exception ex)
            {
                return false;
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900