Link to home
Start Free TrialLog in
Avatar of PianoMover
PianoMoverFlag for Canada

asked on

Sending email in ASP.NET webform on behalf of user completing form

I am trying to figure out the best way to do something that I believe should be simple and is a really common item on websites, but I am failing miserable to impliement the way I think it should work.  On most websites that have a question or message form to fill in, you have a minimum of 3 standard textboxes to fill in: Your Name, Your email Address, Your message.  Now I am making an assumption here that these web forms send an email to the website provider email server in question with the Name & email address in the email from field, the message in the body of the email and the rest is configured by the website form by some preset settings.

I've written this exact procedure in vb asp.net and had it working sending emails to my exchange 2007 server at my office.  Then all I have to do is hit the reply button when I get the email and answer the question.

Now for the problem: I am trying to remove my exchange 2007 server because I don't have the time to maintain the server myself anymore and want to outsource my email service.  I have a google apps for domain account and an office 365 account setup that I am currently experimenting with.  I have modified the code to send to both of these accounts and got them both to receive a test email.  Here's the catch:  The only way it works, is if the from email address is the same as the account I am sending it too, which is basically me.  So I can receive an email from the website, but the from address is always the same (me) and I can never reply to anyones email, because the reply comes back to me since I am now the sender. If I try to send as the user from the input box on the form the email gets rejected from Gmail & Office 365 as a permissions problem (don't have rights to send email on behalf of that email address/user).  Talking with Office 365 tech support this is probably for spam reasons.  Frustrating.  Now I have a wordpress website using cform and it will send an email to the gmail account without a problem (haven't tried office 365 yet) showing the email coming from the user input box, exactly the way I am trying to do in asp.net.  Now I don't want to use wordpress for this function, I need an asp.net website so I can take advantage of some vb code I want to use on the form.  The wordpress cform has obviously found a way around this problem, but I cannot find similar solution in asp.net, remembering that I am trying to down the number of computers/servers that I am maintaining.

I have to believe that someone has run into this same problem out there and that there are lots of asp.net websites doing what I am trying to accomplish.  I really don't want to keep runing this exchange server, but will if I have too.  I believe the key is in the asp.net code I am using, because I didn't do anything special with the wordpress site to make it work with gmail.  Any suggestions/solutions on how to solve my problem?
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PianoMover

ASKER

Thanks emoreau, but I've already read this article prior to posting question and if I follow correctly it is for in house items only (all in one printers).  It also means I still need to have a basic email server on site open to the internet for my website to go through which is what I am trying to get away from.

CodeCruiser:
1. asp.net webform hosted on a 3rd party provider and I am wanting to shoot email from it to an office 365 account which is exchange 2010 server.  

2. I didn't follow what you meant in the first half of the second paragraph, but I tried the replyto option like you suggested and it basically or half accomplishes what I am looking for.  Now here is the spoiled person talking.  Using the replyto option like you suggested functionally works for my main concern, but all the emails coming in now show in my inbox as coming from me or another account I might designate it as instead of the person that was sending it.  I can technically live with it, but I am spoiled from my previous setup where it shows it coming from the user in question who sent it.  This was handy because I could sort by send from in outlook and see all emails from this individual in date received order.  I could put their name in the subject line, but is their any way to put them in the from address as well.  My wordpress website does this and I am wondering whether there is a way in asp.net too?
>You can send the email from your own address but use that person's name in the From

What I meant was that you can set the from email address and name of the message itself to the person but use the email server and credentials of your own (message.from vs smtpclient.credentials)
Code Cruiser:

I've tried putting that person's name in the from field while using my credentials to log into the server, but the email server rejects the email basically saying it is not a valid from address in office 365 and gmail just overwrites the from address with the credentials email address.

The odd part is if I try wordpress and use it's cform to send an email, it works fine with gmail and doesn't even require the credentials.  It is like it is using a different method for sending the email.
They use the "Send on behalf of" feature which allows another user to send email on behalf of someone else. They probably send using their own server but have configured it to allow other users (the one filling the form) to send the email.
Thanks CodeCruiser.  I'm going to use the ReplyTo command to get around my current problem.  It's not the answer I was hoping for, but it definitely will get the job done.