Click to See Complete Forum and Search --> : What is wrong with my E-mail code???


philonous
September 8th, 2005, 07:19 PM
Try
Dim Msg As New MailMessage
Msg.To = "myemail@mydomain.co.uk"
Msg.Subject = TxtSubject.Text
Msg.Body = "<b><u>From</u></b>: " & TxtName.Text & "."
Msg.Body &= "<br><br>" & "<b><u>Message</u></b>: " & "<br><br>"
Msg.Body &= TxtComment.Text
Msg.From = TxtSender.Text
Msg.BodyFormat = MailFormat.Html
SmtpMail.SmtpServer = "localhost"
SmtpMail.Send(Msg)
LblResult.Text = "Message sent successfully!"
Catch ex As Exception
LblResult.Text = ex.Message
End Try



The problem is that I only receive e-mails from that page if the "sender" field has the same domain as the address I'm receiving the e-mail to, the e-mail can be absolutely anything@mydomain.co.uk etc but not anything else, e.g if someone enters that their e-mail address is: "someone@hotmail.com" then it does not get sent to me whereas if they sent it as "someone@mydomain.co.uk" then I would receive it.

The "to" field cannot be seen and thus can not be changed by the user, I don't see how the sender has to say that their e-mail address is coming from the same domain I have!

What am I doing wrong???

p.s for obvious reasons I have used "mydomain.co.uk" instead of my real e-mail address but you get the picture.

CrystalAnnoysMe
September 9th, 2005, 08:42 AM
I know this doesn't directly help you but could be a work around until someone gives you a better answer. Just append the txtFrom box to your message text and throw in a fake msg.from in the meantime so it at least works.

Could it be something with the localhost only allowing people in the @yourdomain group sending rights so it thinks that another email address (someone@hotmail.com) is trying to use its sytems, and thats not allowed?

-Allan.

philonous
September 9th, 2005, 12:37 PM
the weird thing is that the only domain it's letting me use it hosted on a completely different server...maybe it has something to do with the address the e-mail is going to (I'm using that domain to receive the mail).

if I can't get it working I could put in a fake msg.from field i suppose something like myapplication@mydomain.co.uk.

sotoasty
September 9th, 2005, 04:41 PM
I don't think where it is hosted has anything to do with it. An e-mail server should accept any mail for it's designated domain. For example, Any e-mail server will take in any e-mail designated for mydomain.com if it is set up as a mydomain.com mailserver. Even if it has to deliver it to a secondary server to deliver it. However, it won't take mail for otherdomain.com, unless, it can verify that the e-mail is coming from someuser@mydomain.com. If all e-mail servers allowed anymail to come in and go out to any other domain, spam would be even more rampant than it is now. What you will probably need to do, is authenticate you are a valid user of mydomain.com, and are allowed to send to otherdomain.com

Here is an e-mail class that was converted from vb6. I use it in a service to send plain text e-mails to our clients for status updates.


Here is how I use it.

EM = New EMail
EM.RequiresLogin = True
EM.Password = "mypass" ' email account password
EM.UserName = "SoToasty" ' email username may need full e-mail account
EM.EMailFrom = "mymail@mydomain.com"
EM.EMailFromName = "Mr. So Toasty"
EM.EMailType = EMail.EMType.Text
EM.EMailTo = mvarRefEMail ' email address to send to
EM.EMailToName = Trim(mvarRefFName & " " & mvarRefLName) ' proper name of recipient
EM.MailServer = "mail.mydomain.com"
EM.Note = "Email Message To Send"
EM.Subject = "Email Subject"
EM.SendEMail()
EM = Nothing



Don't know if this will help or not but good luck