在Asp.net 3.5中无法发送消息 [英] Failure Sending Message in Asp.net 3.5

查看:87
本文介绍了在Asp.net 3.5中无法发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我在窗口7中发送邮件功能时遇到问题.
我正在使用vs2008,c#和asp.net 3.5.

我正在使用以下代码发送邮件.......

Hi All,
I am facing problem in sending mail functionality in window 7.
I am using vs2008,c# and asp.net 3.5.

I am using following code for sending mail..........

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;

public static void SendMail(string from, string to, string subject, string body)
    {
        MailMessage mailMessage = new MailMessage();
        mailMessage.From = new MailAddress(from);
        mailMessage.To.Add(to);
        mailMessage.Subject = subject;
        mailMessage.IsBodyHtml = true;
        mailMessage.BodyEncoding = Encoding.UTF8;
        mailMessage.Body = body;
        mailMessage.Priority = MailPriority.Normal;

        // Smtp configuration for localhost / gmail 
        SmtpClient client = new SmtpClient();
        client.Credentials = new NetworkCredential("[DELETED]@gmail.com", "mukeshpa"); // enter your user name and password for gmail 
        client.Port = 587; //use 465 or 587 ports for gmail     //use 25          
        client.Host = "smtp.gmail.com";// for gmail            //use "127.0.0.1";
        client.EnableSsl = false; // true for gmail 

        MailMessage message = mailMessage;

        try
        {
            client.Send(message);
            Show("sending mail........");

        }
        catch (Exception ex)
        {
            Show("Sending fail.." + ex.ToString());
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        SendMail(txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);
    }



请帮忙或给我任何建议.......
帮助将不胜感激..........

谢谢
穆克什




please help or any suggestion for me.......
help will be greatly appreciated..........

thanks
mukesh


[edit]Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know - OriginalGriff[/edit]

推荐答案

没有错误消息,很难分辨,但是从注释中看,这可能是错误的:
Without the error message, it is difficult to tell, but from the comments, this might be wrong:
client.EnableSsl = false; // true for gmail


这篇关于在Asp.net 3.5中无法发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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