Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi,
i have hosted my website in godaddy windows server and i have used following codes for sending email using gmail
C#
string myEmailAddress = "enquirefusion@gmail.com";
           string mypwd = "******";
           string toEmailAddress = "sanjay@fusiontechnopower.com";
           string subject = Txtsubject.Text;
           string mailbody = txtname.Text+"\n"+Txtemail.Text+"\n"+Txtbody.Text;

           var client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587)
           {
               Credentials = new System.Net.NetworkCredential(myEmailAddress, mypwd),
               EnableSsl = true
           };
           client.Send(myEmailAddress, toEmailAddress, subject, mailbody);

But i am getting a runtime error on the line
var client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587)

Error says:
CSS
Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Please help me guys i am in great trouble...god bless you
Posted
Updated 31-Oct-13 4:49am
v2

Why don't you look around at godaddy forum[^]? There you have your answer multiple times:
Quote:
When you’re sending mail through your hosting account, be sure you’re using this as your SMTP server: relay-hosting.secureserver.net
As I see you can't use google mail server there....
 
Share this answer
 
Comments
faizel s 31-Oct-13 11:35am    
i used relay-hosting.secureserver.net instead of smtp.gmail.com still it is not working.should i change port id 587 please reply
Zoltán Zörgő 31-Oct-13 14:20pm    
Man! What about a minute of digging on your provider's support pages? Should I do it for you? Why?
Well, I have found the answer. You could have found it too.
http://support.godaddy.com/help/article/5620/configuring-email-with-nopcommerce
faizel s 1-Nov-13 13:25pm    
i am very sorry.i was a little desperate at that time.anyway thank you for helping.god bless you
Godaddy doesn't work well with gmail and others. Use the Godaddy server where you have a mail account. You don't need to supply the server name or port, just your credentials. You probably won't find this mentioned on the godaddy forums or help.
 
Share this answer
 
Comments
faizel s 31-Oct-13 11:39am    
can you give me code for that.please help me
Faisel,
Here is the code in VB.net

Imports System.Net
Imports System.Net.Mail
Partial Class Contact_Us
Inherits System.Web.UI.Page

Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim mm As New MailMessage("sender@x", "recipent@y")
mm.Subject = txtSubject.Text
mm.Body = "Name: " & txtName.Text & "

Email: " & txtEmail.Text & "
" & txtBody.Text
'---------------------
'File attachment below is not used
'If FileUpload1.HasFile Then
'Dim FileName As String = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)
'mm.Attachments.Add(New Attachment(FileUpload1.PostedFile.InputStream, FileName))
'End If
'---------------------
mm.IsBodyHtml = True
Dim smtp As New SmtpClient()
Dim NetworkCred As New System.Net.NetworkCredential()
NetworkCred.UserName = "username"
NetworkCred.Password = "password"
smtp.Credentials = NetworkCred
On Error GoTo errmsg
smtp.Send(mm)
lblMessage.Text = "Message Sent Sucessfully."
Exit Sub
errmsg:
lblMessage.Text = "There was a delivery problem. Go to the loginpage and send an email"

End Sub

End Class
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900