Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Name:aaa
Mobileno:<removed>
Emailaddress:name@gmail.com
Comments:hai
fields are there, now I want to sent this details to mycompany email address. It is possible thanks in advance. But mycompany received mail in Emailaddress field...

What I have tried:

Inbox
Receive mail in name@gmail.com
Posted
Updated 20-Apr-17 9:22am
v3

There are many, many tutorials and examples online. Here is one, [^]

You'll use the System.Net.Mail namespace, SmtpClient Class (System.Net.Mail)[^].
 
Share this answer
 
Comments
sarathtamil 20-Apr-17 7:22am    
here 'to address' is company or site mail address ,how to add network credential?
i have company username and password, but how do i know customer password?
ZurdoDev 20-Apr-17 7:28am    
The credentials are for connecting to your SMTP server.
Dave Kreskowiak 20-Apr-17 7:30am    
WTF? You don't. Why on earth would you add the login credentials of the person your sending the email to? They are not logging into YOUR email server!

The network credentials are there so your code can login to your own SMTP server to send the email.
sarathtamil 20-Apr-17 7:39am    
how to connect sender mail id?
ZurdoDev 20-Apr-17 8:01am    
Sender is you. Or some other email you have access to.
You can try this,

C#
try
            {
                var SendersAddress = "senderemail@gmail.com";
                var SendersPassword = "senderpassword";
                var ccMailId = "ccemail@gmail.com";
                var ReceiversAddress = "name@gmail.com";
                var subject = "Deatils";
                var body = "Name:aaa, Mobileno:9786543210, Emailaddress:name@gmail.com,Comments:hai";
                //we will use Smtp client which allows us to send email using SMTP Protocol
                //i have specified the properties of SmtpClient smtp within{}
                //gmails smtp server name is smtp.gmail.com and port number is 587
                SmtpClient smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    Credentials = new NetworkCredential(SendersAddress, SendersPassword),
                    Timeout = 3000000
                };

                //MailMessage represents a mail message
                //it is 4 parameters(From,TO,subject,body)

                MailMessage message = new MailMessage(SendersAddress, ReceiversAddress, subject, body);
                /*WE use smtp sever we specified above to send the message(MailMessage message)*/

                if (!string.IsNullOrEmpty(ccMailId))
                {
                    message.CC.Add(ccMailId);
                }

                message.BodyEncoding = Encoding.UTF8;
                message.SubjectEncoding = Encoding.UTF8;

                AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body);
                htmlView.ContentType = new System.Net.Mime.ContentType("text/html");
                message.AlternateViews.Add(htmlView);

                smtp.Send(message);
                Console.WriteLine("Message Sent Successfully");
                //Console.ReadKey();
            }
            catch (Exception ex)
            {                
                Console.WriteLine(ex.Message);
                //  Console.ReadKey();
            }
 
Share this answer
 
Comments
sarathtamil 20-Apr-17 7:41am    
i know receiver username and password . how do you know sender password...
Nilesh#555 20-Apr-17 7:44am    
sender address and password are the one from which you are going to send email. create an email account and use those credentials for sending.
sarathtamil 20-Apr-17 7:49am    
in contact us page customer just enter the mobileno , email address AND comments should be added. finally to send message button click.
Nilesh#555 20-Apr-17 7:53am    
Create an test account for sending emails. Customers email address is the one he enters on page. So, sender email are test account details and receiver address should be available on page.

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