从asp.net c sharp Plz发送邮件帮助 [英] Sending mail from asp.net c sharp Plz help

查看:144
本文介绍了从asp.net c sharp Plz发送邮件帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 2008

Visual Studio 2008

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;

public partial class FrmSendMail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress(txtGAddress.Text, "Sender's Name");
        msg.To.Add(new MailAddress(txtToAddress.Text));
        msg.Subject = txtSubject.Text;
        msg.Body = txtMessage.Text;
        msg.IsBodyHtml = true;

        if (fluattachment.HasFile)
        {
            msg.Attachments.Add(new Attachment(fluattachment.PostedFile.InputStream, fluattachment.FileName));

        
        }
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Credentials = new System.Net.NetworkCredential(txtGAddress.Text, txtGPassword.Text);
        LblReason.Visible = true;
        smtp.EnableSsl = true;
        try
        {
            smtp.send(msg);//Getting the error over here//
            LblReason.Text = "Mail Sent";

        }
        catch (Exception ex)
        {
            LblReason.Text = ex.Message;
            
            
        }
    }
}





错误是



错误1''System.Net.Mail.SmtpClient''不包含''send''的定义,也没有扩展方法''send''接受第一个可以找到类型''System.Net.Mail.SmtpClient''的参数(你是否缺少using指令或程序集引用?)C:\ Document and Settings \SALMAN \ My Documents \ Visual Studio 2008 \ nWebSites\Excel1 \FrmSendMail.aspx.cs 44 18 C:\ ... \ Excel1 \



Error is

Error 1 ''System.Net.Mail.SmtpClient'' does not contain a definition for ''send'' and no extension method ''send'' accepting a first argument of type ''System.Net.Mail.SmtpClient'' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\SALMAN\My Documents\Visual Studio 2008\WebSites\Excel1\FrmSendMail.aspx.cs 44 18 C:\...\Excel1\

推荐答案

smtp.Send(fromAddress, toAddress, subject, body);



或者读取 使用SMTP服务器在ASP.NET中发送带附件的电子邮件 [ ^ ]


参考此文章本文将解决您发送带附件的邮件的问题 -



http://www.aspsnippets.com/forums/Articles/How-to-send-email-with-Multiple-Attachments-in-ASPNet-Website.aspx [ ^ ]
Refer this Article this article will solve your problem of sending mail with attachment-

http://www.aspsnippets.com/forums/Articles/How-to-send-email-with-Multiple-Attachments-in-ASPNet-Website.aspx[^]


查看此示例



< add key =MAILEnvioCorrreovalue =Hola {0} ,<峰; br>< / BR> hemos creado una cuenta de Usuario con los siguientes datos:< br>< / br> Usuario:{1}< br>< / br> Contraseña:{2}>

private void EnvioCorreo(Empleado empleado,string clave)

{

#regionCargandotonsiguracióndelservidor de correo

string MailServer =name server example smtp.gmail.com;

string MailServerPort =587;

string MailServerUser =电子邮件或用户;

字符串MailServerPassword =example;

字符串MailServerEnableSSL =如果使用服务器hotmail,gmail,yahoo这个值为false;

#endregion



SmtpClient smtp =新的SmtpClient(MailServer,MailServerPort);

smtp.Credentials = new System.Net。 NetworkCredential(MailServerUser,MailServerPassword);

smtp.EnableSsl = MailServerEnableSSL;

MailAddress sender = new MailAddress(MailServerUser,any thing);

StringBuilder mensaje = new StringBui lder();

StringBuilder mensajeMail = new StringBuilder();

string formatoAvisoMail = System.Configuration.ConfigurationManager.AppSettings [MAILEnvioCorrreo this in app congig]。ToString( );

MailMessage msjMail = new System.Net.Mail.MailMessage();

msjMail.Subject =Bienvenido a Kanan;

msjMail.From =发件人;

msjMail.IsBodyHtml = true;

mensaje.AppendFormat(formatoAvisoMail,empleado.Nombre,empleado.Usuario.Nombre,clave);

mensajeMail.AppendFormat(formatoAvisoMail,empleado.Nombre,empleado.Usuario.Nombre,clave);

msjMail.Body = mensajeMail.ToString();

msjMail.To.Clear();

msjMail.CC.Add(MailServerUser);

msjMail.To.Add(empleado.Email);

if(msjMail.To.Count> 0)

smtp.Send(msjMail);

}
Check this example

<add key="MAILEnvioCorrreo" value=" Hola {0},<br></br> hemos creado una cuenta de Usuario con los siguientes datos:<br></br> Usuario: {1} <br></br> Contraseña: {2}">
private void EnvioCorreo(Empleado empleado, string clave)
{
#region Cargando configuración del servidor de correo
string MailServer = "name server example smtp.gmail.com";
string MailServerPort = ""587;
string MailServerUser = "email or user";
string MailServerPassword = "example";
string MailServerEnableSSL = " if use server hotmail, gmail,yahoo this value is false ";
#endregion

SmtpClient smtp = new SmtpClient(MailServer, MailServerPort);
smtp.Credentials = new System.Net.NetworkCredential(MailServerUser, MailServerPassword);
smtp.EnableSsl = MailServerEnableSSL;
MailAddress sender = new MailAddress(MailServerUser, "any thing");
StringBuilder mensaje = new StringBuilder();
StringBuilder mensajeMail = new StringBuilder();
string formatoAvisoMail = System.Configuration.ConfigurationManager.AppSettings["MAILEnvioCorrreo this in app congig"].ToString();
MailMessage msjMail = new System.Net.Mail.MailMessage();
msjMail.Subject = "Bienvenido a Kanan";
msjMail.From = sender;
msjMail.IsBodyHtml = true;
mensaje.AppendFormat(formatoAvisoMail, empleado.Nombre, empleado.Usuario.Nombre, clave);
mensajeMail.AppendFormat(formatoAvisoMail, empleado.Nombre, empleado.Usuario.Nombre, clave);
msjMail.Body = mensajeMail.ToString();
msjMail.To.Clear();
msjMail.CC.Add(MailServerUser);
msjMail.To.Add(empleado.Email);
if (msjMail.To.Count > 0)
smtp.Send(msjMail);
}


这篇关于从asp.net c sharp Plz发送邮件帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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