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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
sean kehinPosted Nov 12, 2009, 5:32 PM
Posted Nov 12, 2009, 12:25 AM
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 kehinPosted Nov 11, 2009, 8:35 PM
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;
}
sean kehinPosted Nov 10, 2009, 9:04 PM
MailAttachment attach = new MailAttachment(Server.MapPath(FileNmaeToAttach));
message.Attachments.Add(attach);
Kirtan PatelPosted Nov 10, 2009, 4:22 PM
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 kehinPosted Nov 10, 2009, 1:25 PM
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 PatelPosted Nov 10, 2009, 11:39 AM
could not understood what you exactly trying to do ??