如何设置SMTP以接收和发送带附件的电子邮件? [英] How do I setup SMTP to receive and send emails with attachment?

查看:525
本文介绍了如何设置SMTP以接收和发送带附件的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个C#代码来发送,接收和验证发送到网站上的电子邮件,任何助手?

解决方案

为此目的,类 System.Net.Mail.MailMessage 具有属性附件

http://msdn.microsoft.com/en-us/library/System。 Net.Mail.MailMessage%28v = vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.net.mail。 mailmessage.attachments%28v = vs.110%29.aspx [ ^ ]。



第二个l墨水显示添加附件的一些代码示例。



祝你好运。

-SA


试试这个...



MailMessage Msg = new MailMessage();

//发件人电子邮件地址。

Msg.From =新邮件地址(emailAddress);

//收件人电子邮件地址。

Msg.To.Add( 要解决);

Msg.Subject =ADD SUBJECT;

Msg.Body =MSG BODY;

Msg。 IsBodyHtml = true;

//您的远程SMTP服务器IP。

SmtpClient smtp = new SmtpClient();

smtp.Host =smtp .gmail.com;

smtp.Port = 587;

smtp.Credentials = new System.Net.NetworkCredential(FROM ADDRESS(Mail Id),PASSWORD );

smtp.EnableSsl = true;

smtp.Send(MSG);

I need a C# code to send, receive and validate email to put on website, any helpers?

解决方案

For this purpose, the class System.Net.Mail.MailMessage has the property Attachments:
http://msdn.microsoft.com/en-us/library/System.Net.Mail.MailMessage%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.attachments%28v=vs.110%29.aspx[^].

The second link shows some code sample of adding an attachment.

Good luck.
—SA


Try this...

MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(emailAddress);
// Recipient e-mail address.
Msg.To.Add("TO ADDRESS");
Msg.Subject = "ADD SUBJECT";
Msg.Body = "MSG BODY";
Msg.IsBodyHtml = true;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("FROM ADDRESS (Mail Id)", "PASSWORD");
smtp.EnableSsl = true;
smtp.Send(Msg);


这篇关于如何设置SMTP以接收和发送带附件的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆