使用C#发送电子邮件 [英] Sending email with C#

查看:87
本文介绍了使用C#发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i已在godaddy windows服务器上托管我的网站,我使用以下代码使用gmail发送电子邮件

  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);



但我收到运行时错误

 var client = new System.Net.Mail.SmtpClient(smtp.gmail.com,587)



错误说:

 安全性 例外 

描述: application 尝试 执行 操作 允许 by security 策略 grant this application required 权限 contact your system administrator 更改 应用程序的 trust configuration file

异常 详情: 系统安全性 SecurityException: 请求 权限 type 'System Net Mail SmtpPermission 系统,版本= 4. 0 0 0 ,Culture = neutral,PublicKeyToken = b77a5c561934e089'失败



请帮助我们,我很麻烦...上帝保佑你

解决方案

为什么不环顾四周 godaddy论坛 [ ^ ]?你有多次答案:

Quote:

当你通过你的主机帐户发送邮件时,请确保你使用它作为你的SMTP服务器: relay-hosting.secureserver.net

正如我所见,你不能在那里使用谷歌邮件服务器....

Godaddy与gmail和其他人不兼容。使用拥有邮件帐户的Godaddy服务器。您不需要提供服务器名称或端口,只需提供凭据。您可能不会在godaddy论坛或帮助中找到这个。


以下链接将有用:





1> http://social.msdn.microsoft.com/Forums/en-US/a75533eb-131b-4ff3-a3b2-b6df87c25cc8/how-do-i-send-mail-using-c?forum=netfxnetcom [ ^ ]



2> http://stackoverflow.com/questions/17306428/sending-email-from-c-尖锐代码 [ ^ ]



3> http://stackoverflow.com/questions/18326738/how- to-send-email-in-asp-net-c-sharp [ ^ ]





希望有用:

------------------------------

Vishnu Prajapati

Hi,
i have hosted my website in godaddy windows server and i have used following codes for sending email using gmail

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:

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

解决方案

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....


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.


Following Link Will Helpful :


1> http://social.msdn.microsoft.com/Forums/en-US/a75533eb-131b-4ff3-a3b2-b6df87c25cc8/how-do-i-send-mail-using-c?forum=netfxnetcom[^]

2> http://stackoverflow.com/questions/17306428/sending-email-from-c-sharp-code[^]

3> http://stackoverflow.com/questions/18326738/how-to-send-email-in-asp-net-c-sharp[^]


Hopefully Helpful :
------------------------------
Vishnu Prajapati


这篇关于使用C#发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆