我发送邮件,但发送邮件时遇到问题PLZ帮助我 [英] i sending a mail but i am getting problem while sending the mail's plz help me

查看:137
本文介绍了我发送邮件,但发送邮件时遇到问题PLZ帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发送邮件但发送邮件时遇到问题PLZ帮助我

我的代码是 -

  protected   void  Btn_Submit_Click( object  sender,EventArgs e)
{
string style = < span style =颜色:绿色; font-weight:粗体; font-size:14px; >中;
string uid = System.Configuration.ConfigurationSettings.AppSettings [ gmailid]的ToString();
// string mailfromid = System.Configuration.ConfigurationSettings.AppSettings [noreplyid]。ToString();
string mailfrompwd = System.Configuration.ConfigurationSettings.AppSettings [ noreplypwd]的ToString();

string Body = 你订阅了电子报......;
string Subject = 新订阅< /跨度>;
// 电子邮件(mailfromid,mailfrompwd,uid,Body,Subject);
电子邮件(uid,mailfrompwd,uid,Body,Subject);
}

public void 电子邮件( string 来自 string frompwd, string to, string body, string subject)
{

MailMessage mail = new MailMessage();
mail.From = new MailAddress( from );
mail.IsBodyHtml = true ;
NetworkCredential mailAuthentication = new NetworkCredential( from ,frompwd);
SmtpClient smtp = new SmtpClient( smtp .gmail.com 587 );
smtp.EnableSsl = true ;
smtp.UseDefaultCredentials = false ;
smtp.Credentials = mailAuthentication;
mail.To.Add( new MailAddress(to));
mail.Subject = subject;
mail.Body = body;
} < / span >

解决方案

只是一个猜测,但是当你打电话时什么也没发生?



如果是这样,那么也许您应该考虑实际发送电子邮件,而不是构建邮件类实例,然后在方法结束时丢弃它...

要么:

1)在Email方法的底部添加:

 smtp.Send(mail); 





2)请参阅此处了解预建方法:使用或不使用附件在C#中发送电子邮件:通用例程。 [ ^ ]


i sending a mail but i am getting problem while sending the mail's plz help me
my code is -

protected void Btn_Submit_Click(object sender, EventArgs e)
    {
        string style = "<span style="color:Green;font-weight:bold;font-size:14px;">";
        string uid = System.Configuration.ConfigurationSettings.AppSettings["gmailid"].ToString();
        //string mailfromid = System.Configuration.ConfigurationSettings.AppSettings["noreplyid"].ToString();
        string mailfrompwd = System.Configuration.ConfigurationSettings.AppSettings["noreplypwd"].ToString();

        string Body = "You Have Subscribe E-Paper...";
        string Subject = "New Subscription";
       // Email(mailfromid, mailfrompwd, uid, Body, Subject);
        Email(uid, mailfrompwd, uid, Body, Subject);
    }

    public void Email(string from, string frompwd, string to, string body, string subject)
    {
       
        MailMessage mail = new MailMessage();
        mail.From = new MailAddress(from);
        mail.IsBodyHtml = true;
        NetworkCredential mailAuthentication = new NetworkCredential(from, frompwd);
        SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
        smtp.EnableSsl = true;
        smtp.UseDefaultCredentials = false;
        smtp.Credentials = mailAuthentication;
        mail.To.Add(new MailAddress(to));
        mail.Subject = subject;
        mail.Body = body;
    }</span>

解决方案

Just a guess, but does nothing happen when you call that?

If so, then perhaps you should consider actually sending the email, instead of constructing the mail class instance and then discarding it at the end of the method...
Either:
1) Add this at the bottom of the Email method:

smtp.Send(mail);


Or
2) See here for a pre-built method: Sending an Email in C# with or without attachments: generic routine.[^]


这篇关于我发送邮件,但发送邮件时遇到问题PLZ帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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