I have read some codes posted at the forum regarding the topic of Send Email thru asp.net.
I have gone thru your code and modified it as below:
in web.config:
<configuration>
<appSettings>
'here i defined my hotmail as recepient, so senders will send all their enquiries to my hotmail
<add key="MailToAddress" value="myemail@hotmail.com"/>
</appSettings>
<connectionStrings/>
Dim MailFrom As String = txtEmailAddress.Text.Trim
'receiver's email address
Dim MailTo As String = ConfigurationManager.AppSettings("MailToAddress")
Dim MailSubject As String = txtSubject.Text.Trim
Dim MailBody As String = txtBody.Text.Trim
If MailFrom <> "" And MailTo <> "" And MailBody <> "" Then
Try
Dim MailClient = New SmtpClient
MailClient.EnableSsl = True
PnlEmailForm.Visible = False
PnlEmailSentForm.Visible = True
lblMessage.Text = "Your email has been successfully sent to the Store Owner."
Catch SmtpExc As SmtpException
'log errors
lblMessage.Text = SmtpExc.Message
Catch ex As Exception
'log errors
lblMessage.Text = ex.Message
End Try
In IIS:
I have changed my default smtp virtual server, Access --> Relay-->IP address to "127.0.0.1" as well.
I have used this code in my shopping cart project - contact us Form. It's working fine but i have noticed a minor problem. In my hotmail inbox, it's always show the email's From address to my gmail address. I'm wondering how do i show the email's address and
name entered by the sender at my hotmail From address.
Hope someone can help me solve the problem. Thanks in advanced.
noami
Member
4 Points
27 Posts
send email in asp.net 2.0
Aug 14, 2009 06:26 AM|LINK
Hi
I have read some codes posted at the forum regarding the topic of Send Email thru asp.net.
I have gone thru your code and modified it as below:
in web.config:
<configuration>
<appSettings>
'here i defined my hotmail as recepient, so senders will send all their enquiries to my hotmail
<add key="MailToAddress" value="myemail@hotmail.com"/>
</appSettings>
<connectionStrings/>
<system.net>
<mailSettings>
<network host="smtp.gmail.com" port="587" userName="myemail@gmail.com" password="xx" defaultCredentials="false"/>
</smtp>
</mailSettings>
</system.net>
In code behind ( on button click):
Dim MailFrom As String = txtEmailAddress.Text.Trim
'receiver's email address
Dim MailTo As String = ConfigurationManager.AppSettings("MailToAddress")
Dim MailSubject As String = txtSubject.Text.Trim
Dim MailBody As String = txtBody.Text.Trim
If MailFrom <> "" And MailTo <> "" And MailBody <> "" Then
Try
Dim MailClient = New SmtpClient
MailClient.EnableSsl = True
MailClient.Send(MailFrom, MailTo, MailSubject, MailBody)
PnlEmailForm.Visible = False
PnlEmailSentForm.Visible = True
lblMessage.Text = "Your email has been successfully sent to the Store Owner."
Catch SmtpExc As SmtpException
'log errors
lblMessage.Text = SmtpExc.Message
Catch ex As Exception
'log errors
lblMessage.Text = ex.Message
End Try
In IIS:
I have changed my default smtp virtual server, Access --> Relay-->IP address to "127.0.0.1" as well.
I have used this code in my shopping cart project - contact us Form. It's working fine but i have noticed a minor problem. In my hotmail inbox, it's always show the email's From address to my gmail address. I'm wondering how do i show the email's address and name entered by the sender at my hotmail From address.
Hope someone can help me solve the problem. Thanks in advanced.
nijhawan.sau...
All-Star
16432 Points
3174 Posts
Re: send email in asp.net 2.0
Aug 14, 2009 07:36 AM|LINK
Hi,
Well you are suing google smtp, so you would obviously get the mail from same google account.
What you can do is, add the Customer or user name as part of subject or the subject to know who sent this mail, if you want to do it through gmail.
Now sending mail to users involves usage or your own server's smtp, the username being info@yourdomain.com or anything like that.
noami
Member
4 Points
27 Posts
Re: send email in asp.net 2.0
Aug 14, 2009 08:58 AM|LINK
Thanks for the info. I will test it.