Solved

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

Posted on 2009-05-04
11
1,367 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
  • 5
  • 3
  • 3
11 Comments
 
LVL 31

Accepted Solution

by:
RiteshShah earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 31

Expert Comment

by:RiteshShah
Comment Utility
Elham_Seif,

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

Author Comment

by:Elham_Seif
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 31

Expert Comment

by:RiteshShah
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WPF issue with Trigger 2 65
Nameserver and MX Record 2 43
asp.net mvc5 3 35
LINQ question 7 20
There was an incident about the POP3 issue for the double read receipts and delivery receipts in Exchange 2013.  There was huge research been done and found solution for the duplicate mails. Especially when the user gets  duplicate mails.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now