我正在使用Exchange Server发送带有SmtpClient(正在成功发送)的MailMessages,但希望我发送的电子邮件转到我发送的电子邮件地址的已发送文件夹(未发生).
using (var mailMessage = new MailMessage("fromaddress@blah.com", "toaddress@blah.com", "subject", "body"))
{
var smtpClient = new SmtpClient("SmtpHost")
{
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network
};
// Apply credentials
smtpClient.Credentials = new NetworkCredential("smtpUsername", "smtpPassword");
// Send
smtpClient.Send(mailMessage);
}
Run Code Online (Sandbox Code Playgroud)
是否有我缺少的配置,以确保我发送的所有来自"fromaddress@blah.com"的电子邮件都到达他们的已发送文件夹?
嗨,我正在尝试使用system.net.mail.mailmessage发送一个简单的通知.我只是将字符串作为消息体传递.但问题是即使已发送多行消息在字符串中具有正确的"\ r \n"格式信息.在outlook中打开的邮件将显示为一个长单行.但是Outlook中的查看源将以正确的新行格式显示消息.
例如:原始邮件看起来像:
line1
line 2
line 3
Run Code Online (Sandbox Code Playgroud)
但它将在Outlook中显示如下:
line1 line 2 line 3
Run Code Online (Sandbox Code Playgroud)
Outlook中的查看源仍将显示
line1
line 2
line 3
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能使outlook显示正确的换行信息?
我有一个文本,如"你好,\ r \n这是测试\ r \n谢谢"我正在使用MailMessage类发送邮件.我将"IsBodyHtml"属性设置为false.问题是我收到的邮件没有换行符.你能让我知道我错过了什么吗?
我创建一个从邮件服务器获取电子邮件的应用程序 我使用"System.Net.Mail.MailMessage"接收电子邮件.现在我想获取收件箱中的每封电子邮件的"日期和时间".
使用.NET 4中的MailMessage类,我今天发现了一个问题,到目前为止我无法解决.请参阅以下代码:
using (var message = new MailMessage())
{
message.From = new MailAddress(@"uwe.keim@gmail.com", "Uwe Keim");
message.Bcc.Add(new MailAddress(@"uk@zeta-software.de", "Uwe Keim"));
// This fails (see screenshot).
/*1*/ message.To.Add(new MailAddress(@"uk2@zeta-sw.net", "Müller, Fred"));
// This succeeds.
/*2*/ message.To.Add(new MailAddress(@"uk2@zeta-sw.net", "Fred Müller"));
// This also succeeds.
/*3*/ message.To.Add(new MailAddress(@"uk2@zeta-sw.net", "Muller, Fred"));
message.Subject = "Test";
message.Body = "Some text body.";
new SmtpClient().Send(message);
}
Run Code Online (Sandbox Code Playgroud)
这是一个简单的片段,因此发送SMTP邮件.相互努力的线/*1*/,/*2*/并且/*3*/,该行为不同:
每当接收者("To")名称包含德语变音符号(即"Ä","Ö"或"Ü")和逗号(即",")时,接收者会在收到的电子邮件中看到损坏的文本:

正如您在上面的截图(摘自Outlook 2010)中所看到的,"To:"行中有一个神秘的"=?utf-8?Q?M = C3 = BCller".
留下逗号或删除德语变音符号就可以解决这个问题.我已经尝试过Exchange 2003和hmailserver来获得相同的结果. …
我目前正在考虑在C#中序列化一个MailMessage对象,虽然网上有一些示例的变体,但它们会序列化为二进制,这种点错过了IMO点.
我的方法是,我想将MailMessage序列化为RFC2822 eml字符串,下面的代码就是我提出的.
public string SerializeEmail(MailMessageArgs e)
{
string rfc822eml = "";
Guid g = Guid.NewGuid();
lock (g.ToString())
{
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(@"C:\tmpspool");
di.CreateSubdirectory(g.ToString());
string spoolDir = @"C:\tmpspool\" + g.ToString();
SmtpClient Client = new SmtpClient("localhost");
Client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
Client.PickupDirectoryLocation = spoolDir;
Client.Send(e.mailObj);
var files = from file in Directory.EnumerateFiles(spoolDir)
select file;
string serializedEml = files.First();
rfc822eml = File.ReadAllText(serializedEml);
File.Delete(serializedEml);
Directory.Delete(spoolDir);
}
return rfc822eml;
}
Run Code Online (Sandbox Code Playgroud)
它非常讨厌,但确实有效.理想情况下,我会创建一个新的SMTPClient并添加一个Serialize函数,该函数将自动返回rfc822字符串,而不会访问文件系统.
由于我似乎无法使用Visual Studio跟踪SMTPClient.Send函数,因此这种"理想"的处理方式有点棘手.
我已经通过在Peter Huber的POP3MimeClient和POP3MailClient类中添加一些小的更改来整理RFC消息的反序列化,这样我就可以将HDD上的文件或字符串反序列化为MailMessage.
对我唠叨的是,我真的应该能够使用流序列化MailMessaage并将流写入我选择的字符串 - 或 - 文件而不是绕过房子创建基于GUID的文件夹,如上面的代码所做的那样并将文件内容读回字符串...
关于如何使这更优雅的任何指示将非常感激.
谢谢.
我目前正在使用Papercut来测试通过C#中的SMTP服务器连接发送电子邮件.
我需要发送的电子邮件附有文件,但是当我在Papercut上查看电子邮件时,文件似乎没有出现.我确信这些文件正好附加到电子邮件中,因为我可以在MailMessage对象的附件部分看到它们.我的问题是,Papercut是否支持带附件的电子邮件,还是只显示电子邮件并截断附件?
我正在使用此代码通过yahoo SMTP服务器发送SMTP电子邮件,它是我正在编写的个人项目.
using System.Net.Mail;
using System.Net;
SmtpClient theClient = new SmtpClient("smtp.mail.yahoo.com", 465);
theClient.UseDefaultCredentials = false;
theClient.Credentials = new NetworkCredential("username", "password");
theClient.EnableSsl = true;
MailMessage theMessage = new MailMessage("username@yahoo.com",
"to.someone@gmail.com");
theMessage.Subject = "Dave test from C# subject";
theMessage.Body = "Dave test from C# body";
theClient.Send(theMessage);
Run Code Online (Sandbox Code Playgroud)
这是发送SMTP电子邮件的所有标准代码,但是...服务器似乎抛出错误.它强行终止连接.如果我使用其他SMTP服务器(如Gmail,Windows Live或其他各种ISP Smtp服务器),则不会发生这种情况.
这是异常和堆栈跟踪:
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at ConsoleApplication1.Program.Main(String[] args) in E:\dev\ARCSoftware.FTPProcessor\ConsoleApplication1\Program.cs:line 28
Run Code Online (Sandbox Code Playgroud)
我知道问题不是环境问题,因为我可以使用Outlook Express将这些确切的设置发送到同一台服务器.我想知道我是否需要发送证书或其他什么?
如果您或您认识的任何人对此有任何想法,我将非常感谢您的帮助.
我有一个C#服务,它持续运行用户凭证(即不是本地系统 - 我不能改变这个,虽然我想).在大多数情况下,服务似乎运行正常,但是它经常被轰炸并重新启动,没有明显的原因(服务器管理器设置为在崩溃时重新启动服务).
我在做大量的事件日志,我有一个分层的方法,以异常处理,我认为它可以使至少某种意义:
我一直在看是否有任何资源没有正确发布,我开始怀疑我的邮件代码(发送电子邮件).我注意到我没有为MailMessage对象调用Dispose,现在我已经重写了SendMail代码,如下图所示.
的基本问题是:
private static void SendMail(string subject, string html)
{
try
{
using ( var m = new MailMessage() )
{
m.From = new MailAddress("service@company.com");
m.To.Add("user@company.com");
m.Priority = MailPriority.Normal;
m.IsBodyHtml = true;
m.Subject = subject;
m.Body = html;
var smtp = new SmtpClient("mailhost"); …Run Code Online (Sandbox Code Playgroud) 我收到这样的邮件:
目前,我使用 SMTPClient 和 MailMessage 来发送邮件:
MailMessage message = new MailMessage();
message.From = from;
MailAddress to = new MailAddress(destString);
message.To.Add(to);
message.Subject = subject;
smtpClient.Send(message);
Run Code Online (Sandbox Code Playgroud)
如何修改我的代码以发送邮件并按照上面的邮件接收邮件?
经过一番研究,我找到了使用 Interop 的解决方案,但我无法在我的项目中使用它。
var app = new Microsoft.Office.Interop.Outlook.Application();
var item = (Microsoft.Office.Interop.Outlook.MailItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
item.To = abc@gmail.com;
item.Subject = "test";
item.Permission = Microsoft.Office.Interop.Outlook.OlPermission.olDoNotForward;
item.PermissionService = Microsoft.Office.Interop.Outlook.OlPermissionService.olWindows;
item.Send();
Run Code Online (Sandbox Code Playgroud) mailmessage ×10
c# ×9
email ×4
smtpclient ×4
smtp ×3
asp.net ×1
attachment ×1
datetime ×1
diacritics ×1
rfc2822 ×1
rfc822 ×1
send ×1
yahoo ×1