谁能纠正这个程序? [英] can anyone correct this program ?
本文介绍了谁能纠正这个程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用System;
使用System.Net;
使用System.Net.Mail;
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
命名空间MailSend
{
公共部分类Form1:表格
{
public Form1()
{
InitializeComponent() ;
}
private void label3_Click(object sender,EventArgs e)
{
}
private void groupBox2_Enter(object sender,EventArgs e)
{
}
private void Form1_Load(object sender,EventArgs e)
{
}
private void textBox6_TextChanged(object sender,EventArgs e)
{
}
private void groupBox1_Enter(object sender,EventArgs e )
{
}
private void textBox5_TextChanged(object sender,EventArgs e)
{
}
private void btnBrowse_Click(object sender,EventArgs e)
{
OpenFileDialog obj = new OpenFileDialog();
DialogResult res = obj.ShowDialog();
if(res == DialogResult.OK)
{
string fpath;
fpath = obj.FileName;
txtAttachments.Text = fpath;
}
}
private void button1_Click(object sender,EventArgs e)
{
SmtpClient obj = new SmtpClient();
NetworkCredential n = new NetworkCredential(txtFrom.Text,Jeetendra,System.Text.Encoding.UTF8);
msg.From = m;
msg.To.Add(txtTo.Text);
msg.Subject = txtSub.Text;
msg.Body = txtBody.Text;
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
附件a =新附件(txtAttachments.Text);
msg.Attachments.Add(a);
obj.Send(msg);
MessageBox.Show(Mail Sent Successfully ..... !!!!);
}
}
}
我收到以下错误
以下错误即将发生...错误1'System.Net.NetworkCredential的最佳重载方法匹配.NetworkCredential(string,string,string)'有一些无效的参数D:\BE630 \ MailSend \ MailSend \Form1.cs 67 35 MailSend
错误2参数'3':无法从'系统转换。 Text.Encoding'to'string'D:\ BE630 \ MailSend \ MailSend \Form1.cs 67 84 MailSend
错误3当前上下文中不存在名称msgD:\ BE630 \ MailSend \ MailSend \Form1.cs 68 13 MailSend
错误4当前上下文中名称m不存在D:\ BE630 \ MailSend \ MailSend \Form1.cs 68 24 MailSend
错误5当前上下文中不存在名称msgD:\ BE630 \ MailSend \ MailSend\Form1.cs 69 13 MailSend
错误6 nam e'msg'在当前上下文中不存在D:\BE630 \ MailSend \ MailSend \Form1.cs 70 13 MailSend
错误7当前上下文中不存在名称msgD: \BE630 \ MailSend \ MailSend \Form1.cs 71 13 MailSend
错误8当前上下文中不存在名称msgD:\ BE630 \ MailSend \ MailSend \ Form1。 cs 72 13 MailSend
错误9当前上下文中不存在名称msgD:\ BE630 \ MailSend \ MailSend \Form1.cs 74 13 MailSend
错误10名称' msg'在当前上下文中不存在D:\ BE630 \ MailSend \ MailSend \Form1.cs 75 22 MailSend
解决方案
< blockquote>尝试使用以下代码修改。
NetworkCredential n = new NetworkCredential(txtFrom.Text, Jeetendra);
或
NetworkCredential n = new NetworkCredential(txtFrom.Text,Jeet endra,smtp.xmail.com);
谢谢和问候
Anand。 G
参考这个
使用格式化文本编辑器和附件从ASP.NET发送电子邮件 [ ^ ]
希望它将帮助..
using System; using System.Net; using System.Net.Mail; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace MailSend { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void label3_Click(object sender, EventArgs e) { } private void groupBox2_Enter(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void textBox6_TextChanged(object sender, EventArgs e) { } private void groupBox1_Enter(object sender, EventArgs e) { } private void textBox5_TextChanged(object sender, EventArgs e) { } private void btnBrowse_Click(object sender, EventArgs e) { OpenFileDialog obj = new OpenFileDialog(); DialogResult res = obj.ShowDialog(); if (res == DialogResult.OK) { string fpath; fpath = obj.FileName; txtAttachments.Text = fpath; } } private void button1_Click(object sender, EventArgs e) { SmtpClient obj = new SmtpClient(); NetworkCredential n = new NetworkCredential(txtFrom.Text, "Jeetendra", System.Text.Encoding.UTF8); msg.From = m; msg.To.Add(txtTo.Text); msg.Subject = txtSub.Text; msg.Body = txtBody.Text; msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; Attachment a = new Attachment(txtAttachments.Text); msg.Attachments.Add(a); obj.Send(msg); MessageBox.Show("Mail Sent Successfully.....!!!!"); } } }
I am getting following errors
following errors ar coming... Error 1 The best overloaded method match for 'System.Net.NetworkCredential.NetworkCredential(string, string, string)' has some invalid arguments D:\BE630\MailSend\MailSend\Form1.cs 67 35 MailSend
Error 2 Argument '3': cannot convert from 'System.Text.Encoding' to 'string' D:\BE630\MailSend\MailSend\Form1.cs 67 84 MailSend
Error 3 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 68 13 MailSend
Error 4 The name 'm' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 68 24 MailSend
Error 5 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 69 13 MailSend
Error 6 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 70 13 MailSend
Error 7 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 71 13 MailSend
Error 8 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 72 13 MailSend
Error 9 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 74 13 MailSend
Error 10 The name 'msg' does not exist in the current context D:\BE630\MailSend\MailSend\Form1.cs 75 22 MailSend
解决方案
Try with following code modifications.
NetworkCredential n = new NetworkCredential(txtFrom.Text, "Jeetendra");
or
NetworkCredential n = new NetworkCredential(txtFrom.Text, "Jeetendra","smtp.xmail.com");
Thanks & Regards
Anand. G
Refer this
Sending Email from ASP.NET using Formatted Text Editor and Attachments[^]
Hope it will help..
这篇关于谁能纠正这个程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文