不是从Gmail帐户发送电子邮件 [英] Sending an email not from gmail account

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

问题描述

我已经购买了一个注册域名,所以我现在拥有自己公司的邮件帐号,我写了一个函数,下面发送的邮件是电子邮件发送的代码

protected void SendEmail(object发件人,EventArgs e)

{

使用(MailMessage mm = new MailMessage(txtEmail.Text,txtTo.Text))

{

mm.Subject = txtSubject.Text;

mm.Body = txtBody.Text;

if(fuAttachment.HasFile)

{

string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);

mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream,FileName) );

}

mm.IsBodyHtml = false;

SmtpClient smtp = new SmtpClient();

smtp .Host =smtp.gmail.com;

smtp.EnableSsl = true;

NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text,txtPassword.Text);

smtp.UseDefaultCredentials = true;

smtp.Credentials = NetworkCred;

smtp.Port = 587;

smtp.Send(mm);

ClientScript.RegisterStartupScript(GetType(),alert,alert(')已发送电子邮件。');,true);

}

}

现在我的电子邮件是omer@planrbme.com.pk它不是一个gmail帐户所以代替这行smtp.Host =smtp.gmail.com;我应该怎么写



我尝试了什么:



我有尝试使用gmail它可以工作,但我想使用我自己的主机帐户

I have purchased a domain with registration , so I have now mail account of my own company , i wrote a function to send an email below is the code for email sending
protected void SendEmail(object sender, EventArgs e)
{
using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
{
mm.Subject = txtSubject.Text;
mm.Body = txtBody.Text;
if (fuAttachment.HasFile)
{
string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
}
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
}
}
Now as my email is omer@planrbme.com.pk as it is not a gmail account so instead of this line smtp.Host = "smtp.gmail.com"; what should i write

What I have tried:

I have tried with gmail it works but i want to use my own hosting account

推荐答案

取决于您的托管服务 - 他们会告诉您到底要使用什么,但代码我使用在这里:使用或不使用C#发送电子邮件附件:通用例程。 [ ^ ]和我的web.config文件中的Host我使用:

Depends on your hosting service - they will tell you exactly what to use, but the code I use is here: Sending an Email in C# with or without attachments: generic routine.[^] and for Host in my web.config file I use:
<add key="SMTPHost" value="LocalHost"/>


联系托管服务提供商,他们会告诉你smtp要使用的服务器,如果需要使用用户名和密码,如果需要,那么用户名和密码是什么,如果需要ssl等更新代码以使用与smtp服务器匹配的正确详细信息。此信息通常可以在您托管的仪表板中找到。
Contact the hosting provider and they will tell you the smtp server to use, and if you need to use a username and password, and if so what that username and password is, if you need ssl etc. Update your code to use the correct details that match your smtp server. This info can normally be found in the dashboard of your hosting.


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

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