Fórum ENVIO DE EMAIL COM MÚLTIPLAS LINHAS #9079
03/09/2009
0
Como faço para colocar o conteúdo do Listbox no _MailMessage.Body já que são multiplas linhas. Grato
Sidney
protected void Enviar2()
{
MailMessage _MailMessage = new MailMessage();
_MailMessage.Subject = "EMAIL GERENCIAL";
_MailMessage.From = new MailAddress("sidney@terra.com.br");
_MailMessage.Bcc.Clear();
try
{
_MailMessage.To.Clear();
_MailMessage.To.Add(ddlEmail.Text);
_MailMessage.Body = ListBox1.Text;
_MailMessage.IsBodyHtml = true;
_MailMessage.Priority = MailPriority.Normal;
SmtpClient _SmtpClient = new SmtpClient();
_SmtpClient.Send(_MailMessage);
WebMsgBox.Show("MENSAGEM ENVIADA");
}
catch (Exception Ex)
{
WebMsgBox.Show(Ex.Message);
}
}
Sidney Mendonça/
Curtir tópico
+ 0Posts
03/09/2009
Fabio Mans
aspx
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>teste1</asp:ListItem>
<asp:ListItem>teste2</asp:ListItem>
<asp:ListItem>teste3</asp:ListItem>
<asp:ListItem>teste4</asp:ListItem>
</asp:ListBox>
<asp:TextBox ID="ddlEmail" runat="server"></asp:TextBox>
</div>
</form>
c#
public partial class Email : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (ListItem li in ListBox1.Items)
{
EnviaEmail(li.Value);
}
}
private void EnviaEmail(string body)
{
MailMessage _MailMessage = new MailMessage();
_MailMessage.Subject = "EMAIL GERENCIAL";
_MailMessage.From = new MailAddress("sidney@terra.com.br");
_MailMessage.Bcc.Clear();
try
{
_MailMessage.To.Clear();
_MailMessage.To.Add(ddlEmail.Text);
_MailMessage.Body = body;
_MailMessage.IsBodyHtml = true;
_MailMessage.Priority = MailPriority.Normal;
SmtpClient _SmtpClient = new SmtpClient();
_SmtpClient.Send(_MailMessage);
WebMsgBox.Show("MENSAGEM ENVIADA");
}
catch (Exception Ex)
{
WebMsgBox.Show(Ex.Message);
}
}
}
Se a sua opção for pelo for faça o seguinte.
for (int i = 0; i <= ListBox1.Items.Count - 1; i++)
{
EnviaEmail(ListBox1.Items[i].Value);
}
Espero ter ajudado.
Fabio
Gostei + 0
03/09/2009
Sidney Mendonça/
Gostei + 0
03/09/2009
Fabio Mans
Gostei + 0
04/09/2009
Sidney Mendonça/
Gostei + 0
08/09/2009
Fabio Mans
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder corpoEmail = new StringBuilder();
for (int i = 0; i <= ListBox1.Items.Count - 1; i++)
corpoEmail.AppendFormat("<br>", ListBox1.Items[i].Value);
EnviaEmail(corpoEmail.ToString());
}
Para cada linha do seu List você adiciona na String, no final envia o e-mail.
Espero ter ajudado.
Fabio
Gostei + 0
24/09/2009
Sidney Mendonça/
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)