Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding "Send to a friend" function to my website like www.BBC.COM

Posted on 2009-05-04
11
Medium Priority
?
1,391 Views
Last Modified: 2013-12-17
Please read to the end to see what my proble is.
I have no problem sendig emails.
I'd like to add "Send to a friend" function to my website.
This function will get three things from the user:
1- His/her Name.
2- His/her Email address.(like myemail@dddd.com)
3- His/her friend Email address.(like myFriend@ddd.com)
Then I send an email to myFriend@ddd.com and add a text as the body of the email.
What I'd like to do is that I want to put myemail@dddd.com (user's email address) as the Sender of my email but It gives me the error. I have to set the Sender to an email from my website that I'v authenticate it in SMTP.
Some websites are doing it. For example www.BBC.com, if you try to "send to a friend", it'll set your email address as the Sender of the email to your friend just like you logged in to your email and send an email to your friend!
Do you know how they can do it. And what is the way I can do it too.
Thanks in advance for your time and answers

MailMessage message = new MailMessage();        
      //  message.From = new MailAddress("myemail@dddd.com"); // it's what I'd like to do but it give me an error, So I have to set the sender to an email from my website.
       message.From = new MailAddress("contact@sharplabelcutter.com");        
        message.To.Add(new MailAddress("myFriend@ddd.com"));            
        SmtpClient client = new SmtpClient();            
 
               try
        {
            message.Body = Mytext ;
            message.Subject = "send to a friend";
            client.Send(message);
            
                    }
        catch
        {
         giveError();
        }

Open in new window

0
Comment
Question by:Elham_Seif
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 31

Accepted Solution

by:
RiteshShah earned 2000 total points
ID: 24301887
can't you use below function? for more details, have a look at my small article at:

http://www.sqlhub.com/2008/05/email-sending-script-from-c.html



public string AuthenticatedMailSend(string mailFrom,string mailTo, string Subject, string MessageBody)
        {
            mailFrom = "myemail@dddd.com";
            mailTo = "myFriend@ddd.com";
 
            System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage(mailFrom, mailTo);
            email.Subject = Subject;
            email.IsBodyHtml = true;
            email.Body = MessageBody;
 
            System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
            System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("yournetworkAuthenticationID/Email", "Password");
            mailClient.Host = "";
            mailClient.Port = 25;
            mailClient.UseDefaultCredentials = false;
            mailClient.Credentials = basicAuthenticationInfo;
 
            try
            {
                mailClient.Send(email);
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
 
            return "1";
        }

Open in new window

0
 
LVL 26

Expert Comment

by:jar3817
ID: 24304445
You're probably getting an error because you're effectively forging the FROM address on this email, and in this day and age of spam, that is not a good thing to do.

Try using one of your email addresses as the from address but with their name associated with it:

message.From = new MailAddress("Mike Smith <contact@sharplabelcutter.com>");

Obviously you should substitute the first and last name from your web form. This way when the email lands in the recipient's box, it just says it's from "Mike Smith" who they know, but the actual from address is you (which it should be). You can also set a reply-to address to that of the person filling out the form, that why if the recipient replies with a "thanks" it goes to the original person using the website rather than you.

0
 

Author Comment

by:Elham_Seif
ID: 24312970
Hi  jar3817
I agree with you but how come www.BBC.com can do it? Did you test it?
It's interesting for me how they can do it. Your freind will receive an email which it's Sender is you instead of BBC!!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:RiteshShah
ID: 24312982
Elham_Seif,

what about the script I gave you? have you tried it?
0
 

Author Comment

by:Elham_Seif
ID: 24313400
Hi RiteshShah
I'd like to test your code but I don't know what to set for yournetworkAuthenticationID in line:
      System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("yournetworkAuthenticationID/Email", "Password");
How can I find it?
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24313425
if you are using your own email server than use it's ID/Pass and if you are using service from vendor than tell them you want to send "Authenticated email" from your script, what should be the credentials, they will help you for sure.
0
 
LVL 26

Expert Comment

by:jar3817
ID: 24313687
BBC can do it because they don't care if the message actually gets delivered. I just tried on their site and the message landed in my spam box because their system breaks things like SPF validation. Their server isn't authorized to send mail using my domain in the FROM address.
0
 

Author Comment

by:Elham_Seif
ID: 24329012
Hi RiteshShah
Thanks for your comments. I should ask my vendor about credentials. On Satarday I can ask them and check to see if it works. I really hope so.
0
 

Author Comment

by:Elham_Seif
ID: 24329098
Hi JAR3817
Thanks for your checking BBC. I have tested it in many cases. Yahoo emails and my own website get the emails correctly in my inbox. But sometimes they go to SPAM folder.
It seems that they shouldn't be authorized to do this but that's what they're doing!
And if they can do this trick, we should also be able to do.
0
 
LVL 26

Expert Comment

by:jar3817
ID: 24329588
In you original post, you said it gives you an error when trying to spoof the sender address. What exactly is the error?
0
 

Author Closing Comment

by:Elham_Seif
ID: 31623702
Thanks.
The first code worked for me.
System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage(mailFrom, mailTo);
     email.Subject = mySubject;
     email.IsBodyHtml = true;
     email.Body = myEmailBody;

     System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient();
     System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("anEmailFromMyHost", "myPassword", "myHost");    
     mailClient.Port = 25;
     mailClient.UseDefaultCredentials = false;
     mailClient.Credentials = basicAuthenticationInfo;

     try
     {
         mailClient.Send(email);
     }
     catch (Exception ex)
     {
         return ex.ToString();
     }
 
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question