here is my code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Questionnaire.aspx.cs" Inherits="Questionnaire" %>
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 10, 2009, 6:39 AM EST
could not understood what you exactly trying to do ??
sean kehin11 reputationPosted Nov 10, 2009, 8:25 AM EST
The issue is how to pass my .aspx completed page to the body of my send email function.
private void SendMail()
{
string mailServerName = "XXXX";
MailMessage message = new MailMessage();
message.To.Add("[email protected]");
message.From = new MailAddress("[email protected]");
message.Subject = "New Application";
message.Body = body;
message.IsBodyHtml = true;
SmtpClient mailClient = new SmtpClient();
mailClient.Host = mailServerName;
mailClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
mailClient.Send(message);
message.Dispose();
}
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 10, 2009, 11:22 AM EST
here is How you can attach File to Mail
private void SendMail()
{
string mailServerName = "XXXX";
MailMessage message = new MailMessage();
message.To.Add("[email protected]");
message.From = new MailAddress("[email protected]");
message.Subject = "New Application";
MailAttachment attach = new MailAttachment(Server.MapPath(FileNmaeToAttach));
message.Attachments.Add(attach);
message.Body = body;
message.IsBodyHtml = true;
SmtpClient mailClient = new SmtpClient();
mailClient.Host = mailServerName;
mailClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
mailClient.Send(message);
message.Dispose();
}
if it helps you then check "Do you like this answer" checkbox please :)
sean kehin11 reputationPosted Nov 10, 2009, 4:04 PM EST
MailAttachment attach = new MailAttachment(Server.MapPath(FileNmaeToAttach));
message.Attachments.Add(attach);
sean kehin11 reputationPosted Nov 11, 2009, 3:35 PM EST
public string newApp()
{
WebRequest newAppliction = WebRequest.Create("http://localhost:4101/airnzTcard/Default.aspx");
//newAppliction.Method = "POST";
WebResponse response = newAppliction.GetResponse();
//Stream responseStream = response.GetResponseStream();
StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
sr.Close();
response.Close();
return result;
}
Posted Nov 11, 2009, 7:25 PM EST
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;
namespace consolemail
{
class Program
{
static void Main(string[] args)
{
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
System.Net.NetworkCredential AuthInfo = new
System.Net.NetworkCredential("[email protected]", "babilona");
message.To.Add("[email protected]");
message.Subject = "Test Mail using System.Net.Mail";
message.From = new MailAddress("[email protected]");
string str = "Hai to all";
message.Body = str;
bool isBodyHtml = true;
message.IsBodyHtml = isBodyHtml;
message.Attachments.Add(new Attachment("c:\\something.txt"));
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Priority = MailPriority.High;
smtp.Host = "smtp.gmail.com";
smtp.UseDefaultCredentials = false;
smtp.Credentials = AuthInfo;
smtp.Timeout = 20000;
smtp.Port = 587;
// use stmp.port = 587 if 465 does not work.
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
try
{
smtp.Send(message);
Console.WriteLine("E-mail has been sent succesfully");
Console.ReadLine();
}
catch (System.Net.Mail.SmtpException ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
}
Replace with respective gmail id's and attachment as shown in bold....
Finally create a windows service application to run this on a daily basis in the server....
Hope this help...
---------------------------------------------------------------------------------------------------
If my code in someway helped u don't forget to tick it as correct answer..
sean kehin11 reputationPosted Nov 12, 2009, 12:32 PM EST